import 'dart:async';
import 'dart:convert' as convert;
import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:ui' as ui;

import 'package:animations/animations.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:get/get.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sp_util/sp_util.dart';
import 'package:stop_watch_timer/stop_watch_timer.dart';
import 'package:video_player/video_player.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/Xwidgets/line.dart';
import 'package:yp/Xwidgets/video_thumb.dart';
import 'package:yp/config/config.dart';
import 'package:yp/config/event_bus.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/mall_app/goods_detail/get_coupon.dart';
import 'package:yp/pages/mall_app/goods_detail/ratting_widget.dart';
import 'package:yp/services/api.dart';
import 'package:yp/utils/util.dart';

import '../../../../utils/videoplayer/video_player_plus.dart';
import '../../../router.dart';
import 'goodsPhotoGalleryPage.dart';
import 'item/image_widget.dart';
import 'logic.dart';

import 'package:yp/pages/address_selector/address_model.dart';

class GoodsDetailPage extends StatefulWidget {
  GoodsDetailPage();

  @override
  State<StatefulWidget> createState() => _GoodsDetailPageState();
}

class _GoodsDetailPageState extends State<GoodsDetailPage>
    with SingleTickerProviderStateMixin {
  GlobalKey<ImageWidgetState> imageWidgetKey = GlobalKey();
  GlobalKey _titleHeightKey = GlobalKey();
  double _titleHeightOffsetY;
  GlobalKey _commentLayoutKey = GlobalKey();
  double _commentLayoutOffsetY;
  GlobalKey _richContentLayoutKey = GlobalKey();
  double _richContentLayoutOffsetY;
  bool _kIsWeb = kIsWeb;

  final ScrollController _scrollController = ScrollController();
  final logic = Get.put(GoodsDetailLogic());
  final state = Get.find<GoodsDetailLogic>().state;

  _GoodsDetailPageState() {
    if (Get.arguments != null) {
      logic.itemNumId = Get.arguments["itemNumId"];
      logic.styleNumId = Get.arguments["styleNumId"];
      logic.shopId = Get.arguments["shopId"]?.toString();
    } else {
      logic.itemNumId = getQueryVariable('itemNumId');
      logic.styleNumId = getQueryVariable('styleNumId');
      logic.shopId = getQueryVariable('shopId');
      // if (SpUtil.getInt('empeNumId') == 0 ||
      //     SpUtil.getInt('empeNumId') == null) {
      //   Get.offAllNamed(RouteConfig.mallLogin, arguments: arguments);
      //   return;
      // }
    }
  }

  @override
  void initState() {
    super.initState();

    getCurrentLocationInfo(success: (data) {
      var addressAllString = data['addressAllString'];
      var addressInfo = data['addressInfo'];
      state.addressAllString = addressAllString;
      state.addressInfo = addressInfo;
      changeSelectAddress(addressInfo);
      logic.requestDetail();
    });
    state.pageTitleTabController = TabController(length: 3, vsync: this);
    _scrollController.addListener(() {
      if (_scrollController.offset > 500) {
        eventBus.fire(PlayVideoEvent(false));
      }
    });
  }

  double initOffsetY(GlobalKey key) {
    if (key.currentContext == null) {
      return null;
    }
    RenderBox renderBox = key.currentContext.findRenderObject();
    return renderBox.localToGlobal(Offset.zero).dy;
  }

  void initViewsAnchor(String from) {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _titleHeightOffsetY = initOffsetY(_titleHeightKey);
      // print("Dust---_titleHeightOffsetY = $_titleHeightOffsetY");
      _commentLayoutOffsetY = initOffsetY(_commentLayoutKey);
      if (_commentLayoutOffsetY != null) {
        _commentLayoutOffsetY -= _titleHeightOffsetY;
        // print("Dust---_commentLayoutOffsetY = $_commentLayoutOffsetY");
      }
      _richContentLayoutOffsetY = initOffsetY(_richContentLayoutKey);
      if (_richContentLayoutOffsetY != null) {
        _richContentLayoutOffsetY -= _titleHeightOffsetY;
        // print("Dust---_richContentLayoutOffsetY = $_richContentLayoutOffsetY");
      }
    });
  }

  void downloadOrGoToApp() {
    Future.delayed(Duration(seconds: 1), () {
      if (isWechat()) {
        // toast('请在系统浏览器打开本页面');
        setState(() {
          state.showTip = true;
        });
      } else {
        /// 进入下载页
        webpay(Config.WEB_DOWN_URL +
            "download.html?isGoodsDetail=1&itemNumId=${logic.itemNumId}&shopId=${logic.shopId}&styleNumId=${logic.styleNumId}&typeIndex=${state.typeIndex}");
      }
    });
    webpay(
        "yinpinhui://zrhsh.com/app?isGoodsDetail=1&itemNumId=${logic.itemNumId}&shopId=${logic.shopId}&styleNumId=${logic.styleNumId}&typeIndex=${state.typeIndex}");
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Scaffold(
          body: GetBuilder<GoodsDetailLogic>(
            builder: (logic) {
              if (state.goodsDetail == null) {
                return Center(child: CircularProgressIndicator());
              }
              return Column(
                children: [
                  Expanded(
                    child: Stack(
                      children: [
                        SingleChildScrollView(
                          controller: _scrollController,
                          child: Container(
                            padding: EdgeInsets.only(
                                bottom: (100.w +
                                    (state.deliveryType == 0 ? 80.w : 0.w))),
                            color: Colors.white,
                            child: Column(
                              children: [
                                _banner(), // 轮播图
                                Visibility(
                                  visible: state.goodsDetail['spec_item_detail']
                                          ['is_seckill'] ==
                                      1,
                                  child: _secondsKillRow(),
                                ), // 秒杀倒计时
                                Visibility(
                                  visible: state.goodsDetail['spec_item_detail']
                                              ['ecactivity_classify'] ==
                                          2 &&
                                      state.goodsDetail['spec_item_detail']
                                              ['seckill_status'] ==
                                          1,
                                  child: _secondsKillRowNo(),
                                ),
                                _titleAndPriceLayout(), //标题信息
                                _divider(10),
                                Visibility(
                                  visible: state.typeIndex == 0,
                                  child: _promotionWidget(),
                                ), // 促销
                                Visibility(
                                  visible: state.typeIndex == 0 &&
                                      state.goodsDetail['spec_item_detail']
                                              ['is_seckill'] !=
                                          1,
                                  child: _couponsLayout(),
                                ), // 领券
                                Visibility(
                                  visible: state.SurprisetaskVisible,
                                  child: _surpriseTaskRow(),
                                ), //活动
                                _divider(10),
                                _distributionMannerWidget(), // 配送方式
                                _divider(10),
                                _selectedWidget(), // 已选
                                _divider(10),
                                // 收货地址
                                _receiveAddress(),
                                (state.addressAllString.length > 0)
                                    ? _divider(10)
                                    : Container(),
                                _commentLayout(), // 评论
                                _divider(10),
                                shopInfoWidget(), // 店铺查看
                                _divider(10),
                                _recommendGoodsModule(), // 推荐商品
                                _divider(10),
                                _specificationParametersWidget(), // 规格参数
                                _divider(10),
                                richTextDetailLayout(), // 图文详情
                              ],
                            ),
                          ),
                        ),
                        _pageTitle(), // 导航
                        _overDeliveryTipView(),
                      ],
                    ),
                  ),
                  _bottomPay(), // 底部支付按钮
                ],
              );
            },
          ),
        ),
        if (state.showTip)
          InkWell(
            onTap: () {
              setState(() {
                state.showTip = !state.showTip;
              });
            },
            child: Container(
              color: Colors.black45.withOpacity(.75),
              child: Center(
                  child: Text(
                "请点击右上角的'...'\n然后选择在浏览器打开",
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                ),
                textAlign: TextAlign.center,
              )),
            ),
          ),
      ],
    );
  }

  ///底部支付按钮
  Widget _bottomPay() {
    num store = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['store']
        : 0;
    if (imageWidgetKey.currentState != null) {
      imageWidgetKey.currentState.onPressed(state.favorite_sign ?? false);
    }
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          top: BorderSide(
            color: Color(0xffe0e0e0),
            width: 1,
          ),
        ),
      ),
      width: MediaQuery.of(context).size.width,
      height: 55,
      child: state.typeIndex == 0
          ? Row(
              children: [
                state.goodsDetail['fresh_type'] == 8
                    ? SizedBox(width: 12, height: 10)
                    : Padding(
                        padding: const EdgeInsets.only(left: 12, right: 20),
                        child: GestureDetector(
                          onTap: () {
                            print('跳转购物车 点击事件！！！');
                            if (_kIsWeb) {
                              downloadOrGoToApp();
                            } else {
                              if (SpUtil.getString('token') == null ||
                                  SpUtil.getString('token').isEmpty) {
                                Get.toNamed(RouteConfig.mallLogin, arguments: {
                                  'itemNumId': logic.itemNumId,
                                  'styleNumId': logic.styleNumId,
                                  'shopId': logic.shopId,
                                  'typeIndex': state.typeIndex,
                                }).then((value) {
                                  if (SpUtil.getString('token') != null &&
                                      SpUtil.getString('token').isNotEmpty) {
                                    logic.requestDetail();
                                  }
                                });
                              } else {
                                Get.offAllNamed(RouteConfig.main,
                                    arguments: {'shoppingCart': '2'});
                              }
                            }
                          },
                          behavior: HitTestBehavior.opaque,
                          child: Image.asset(
                            'assets/images/shopping_car_9.png',
                            width: 20,
                            height: 20,
                          ),
                        ),
                      ),

                /// 收藏
                GestureDetector(
                  onTap: () {
                    if (_kIsWeb) {
                      downloadOrGoToApp();
                    } else {
                      if (SpUtil.getString('token') == null ||
                          SpUtil.getString('token').isEmpty) {
                        Get.toNamed(RouteConfig.mallLogin, arguments: {
                          'itemNumId': logic.itemNumId,
                          'styleNumId': logic.styleNumId,
                          'shopId': logic.shopId,
                          'typeIndex': state.typeIndex,
                        }).then((value) {
                          if (SpUtil.getString('token') != null &&
                              SpUtil.getString('token').isNotEmpty) {
                            logic.requestDetail();
                          }
                        });
                      } else {
                        if (state.favorite_sign == false) {
                          var params = {
                            "use_platform": 2,
                            "style_num_id": logic.styleNumId,
                            // "ec_shop_num_id": SpUtil.getInt('storeShopNum')?.toString(),
                            "ec_shop_num_id": logic.shopId,
                            "access_token": SpUtil.getString("token")
                          };
                          Api.addGoodsToFavorite(params).listen((event) {
                            if (event['code'] == 0) {
                              toast('加入收藏成功');
                              state.favorite_sign = true;
                            }
                            imageWidgetKey.currentState
                                .onPressed(state.favorite_sign);
                          });
                        } else {
                          var params = {
                            'style_num_id': logic.styleNumId,
                            'ec_shop_num_id': logic.shopId,
                            'access_token': SpUtil.getString('token'),
                          };
                          Api.collectListsDelete(params).listen((event) {
                            if (event['code'] == 0) {
                              toast('取消收藏成功');
                              state.favorite_sign = false;
                            }
                            imageWidgetKey.currentState
                                .onPressed(state.favorite_sign);
                          });
                        }
                        // logic.requestAddToFavorite();
                      }
                    }
                  },
                  behavior: HitTestBehavior.opaque,
                  child: ImageWidget(
                    imageWidgetKey,
                    state.favorite_sign,
                  ),
                ),
                Offstage(
                  offstage: state.keFuString == null || state.keFuString == '',
                  child: Padding(
                    padding: EdgeInsets.only(left: 20, right: 20),
                    child: GestureDetector(
                      onTap: () {
                        print('联系客服');
                        // if (_kIsWeb) {
                        //   webpay(
                        //       "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN");
                        //   return;
                        // }
                        if (_kIsWeb) {
                          /// 跳转到app失败 进入下载页或者提示系统浏览器打开
                          downloadOrGoToApp();
                          return;
                        }
                        gotoHelpDesk();
                        // Get.toNamed(RouteConfig.webview, arguments: {
                        //   "url":
                        //       "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN",
                        // });
                      },
                      behavior: HitTestBehavior.opaque,
                      child: Image.asset(
                        'assets/images/service_9.png',
                        width: 20,
                        height: 20,
                      ),
                    ),
                  ),
                ),
                Spacer(),
                _overDeliveryView(),

                /// 普通商品加入购物车
                Visibility(
                  visible: store != null &&
                      store > 0 &&
                      !_kIsWeb &&
                      state.deliveryType == 1 &&
                      state.goodsDetail['fresh_type'] != 8,
                  child: GestureDetector(
                    onTap: () {
                      if (SpUtil.getString('token') == null ||
                          SpUtil.getString('token').isEmpty) {
                        Get.toNamed(RouteConfig.mallLogin, arguments: {
                          'itemNumId': logic.itemNumId,
                          'styleNumId': logic.styleNumId,
                          'shopId': logic.shopId,
                          'typeIndex': state.typeIndex,
                        }).then((value) {
                          if (SpUtil.getString('token') != null &&
                              SpUtil.getString('token').isNotEmpty) {
                            logic.requestDetail();
                          }
                        });
                      } else {
                        String itemNumId =
                            state.goodsDetail['spec_item_detail'] != null
                                ? state.goodsDetail['spec_item_detail']
                                        ['item_num_id']
                                    ?.toString()
                                : '';
                        // String ecShopNumId =
                        //     SpUtil.getInt('storeShopNum')?.toString();
                        // String ecShopNumId = state.goodsDetail['shop_num_id']
                        //         ?.toString() ??
                        //     SpUtil.getObject(Config.GET_SHOP_INFO)['shop_id']
                        //         ?.toString();

                        String ecShopNumId =
                            state.shopInfos['shop_id'].toString();
                        String styleNumId =
                            state.goodsDetail['style_num_id']?.toString();
                        String ecStyleNumId =
                            state.goodsDetail['spec_item_detail'] != null
                                ? state.goodsDetail['spec_item_detail']
                                        ['ec_style_num_id']
                                    ?.toString()
                                : '';
                        logic.requestAddGoods(
                            ecShopNumId, itemNumId, styleNumId, ecStyleNumId);
                      }
                    },
                    child: Container(
                      height: 38,
                      padding: EdgeInsets.symmetric(horizontal: 8),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: Color(0xFF210F0F),
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(19),
                          bottomLeft: Radius.circular(19),
                        ),
                      ),
                      child: Text(
                        '加入购物车',
                        style: TextStyle(
                          fontSize: 14,
                          color: Colors.white,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ),
                  ),
                ),
                Visibility(
                  visible:
                      (store != null && store > 0 && state.deliveryType == 1),
                  child: GestureDetector(
                    onTap: () {
                      if (_kIsWeb) {
                        /// 跳转到app失败 进入下载页或者提示系统浏览器打开
                        downloadOrGoToApp();
                      } else {
                        if (SpUtil.getString('token') == null ||
                            SpUtil.getString('token').isEmpty) {
                          Get.toNamed(RouteConfig.mallLogin, arguments: {
                            'itemNumId': logic.itemNumId,
                            'styleNumId': logic.styleNumId,
                            'shopId': logic.shopId,
                            'typeIndex': state.typeIndex,
                          }).then((value) {
                            if (SpUtil.getString('token') != null &&
                                SpUtil.getString('token').isNotEmpty) {
                              logic.requestDetail();
                            }
                          });
                        } else {
                          immediatelyBuy();
                        }
                      }
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8),
                      height: 38,
                      margin: EdgeInsets.only(right: 8),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: Color(0xFFEA5504),
                        borderRadius:
                            !_kIsWeb && state.goodsDetail['fresh_type'] != 8
                                ? BorderRadius.only(
                                    topRight: Radius.circular(19),
                                    bottomRight: Radius.circular(19),
                                  )
                                : BorderRadius.circular(19),
                      ),
                      child: Text(
                        '${state.goodsDetail['fresh_type'] == 8 ? "     " : ''}立即购买${state.goodsDetail['fresh_type'] == 8 ? "     " : ''}',
                        style: TextStyle(
                          fontSize: 14,
                          color: Colors.white,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ),
                  ),
                ),
                Visibility(
                  visible: ((store == null || store <= 0) &&
                      state.deliveryType == 1),
                  child: Container(
                    width: 100,
                    height: 34,
                    margin: EdgeInsets.only(right: 8),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Color(0xFFCCCCCC),
                      borderRadius: BorderRadius.all(Radius.circular(17)),
                    ),
                    child: Text(
                      '已售罄',
                      style: TextStyle(
                        fontSize: 14,
                        color: Colors.white,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
              ],
            )
          : state.typeIndex == 1
              ? Container(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(40)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        children: [
                          GestureDetector(
                            onTap: () {
                              if (_kIsWeb) {
                                downloadOrGoToApp();
                              } else {
                                if (SpUtil.getString('token') == null ||
                                    SpUtil.getString('token').isEmpty) {
                                  Get.toNamed(RouteConfig.mallLogin,
                                      arguments: {
                                        'itemNumId': logic.itemNumId,
                                        'styleNumId': logic.styleNumId,
                                        'shopId': logic.shopId,
                                        'typeIndex': state.typeIndex,
                                      }).then((value) {
                                    if (SpUtil.getString('token') != null &&
                                        SpUtil.getString('token').isNotEmpty) {
                                      logic.requestDetail();
                                    }
                                  });
                                } else {
                                  if (state.favorite_sign == false) {
                                    var params = {
                                      "use_platform": 2,
                                      "style_num_id": logic.styleNumId,
                                      // "ec_shop_num_id": SpUtil.getInt('storeShopNum')?.toString(),
                                      "ec_shop_num_id": logic.shopId,
                                      "access_token": SpUtil.getString("token")
                                    };
                                    Api.addGoodsToFavorite(params)
                                        .listen((event) {
                                      if (event['code'] == 0) {
                                        toast('加入收藏成功');
                                        state.favorite_sign = true;
                                      }
                                      imageWidgetKey.currentState
                                          .onPressed(state.favorite_sign);
                                    });
                                  } else {
                                    var params = {
                                      'style_num_id': logic.styleNumId,
                                      'ec_shop_num_id': logic.shopId,
                                      'access_token': SpUtil.getString('token'),
                                    };
                                    Api.collectListsDelete(params)
                                        .listen((event) {
                                      if (event['code'] == 0) {
                                        toast('取消收藏成功');
                                        state.favorite_sign = false;
                                      }
                                      imageWidgetKey.currentState
                                          .onPressed(state.favorite_sign);
                                    });
                                  }
                                  // logic.requestAddToFavorite();
                                }
                              }
                            },
                            behavior: HitTestBehavior.opaque,
                            child: ImageWidget(
                              imageWidgetKey,
                              state.favorite_sign,
                            ),
                          ),
                          Offstage(
                            offstage: state.keFuString == null ||
                                state.keFuString == '',
                            child: Padding(
                              padding: EdgeInsets.only(left: 20, right: 20),
                              child: GestureDetector(
                                onTap: () {
                                  print('联系客服');
                                  // if (_kIsWeb) {
                                  //   webpay(
                                  //       "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN");
                                  //   return;
                                  // }
                                  if (_kIsWeb) {
                                    downloadOrGoToApp();
                                  } else {
                                    gotoHelpDesk();
                                    // Get.toNamed(RouteConfig.webview,
                                    //     arguments: {
                                    //       "url":
                                    //           "https://ykf-webchat.7moor.com/wapchat.html?accessId=${state.keFuString}&fromUrl=&urlTitle=&language=ZHCN",
                                    //     });
                                  }
                                },
                                behavior: HitTestBehavior.opaque,
                                child: Image.asset(
                                  'assets/images/service_9.png',
                                  width: 20,
                                  height: 20,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      state.deliveryType == 0
                          ? Container(
                              child: _overDeliveryView(),
                            )
                          : store == null || store != null && store <= 0
                              ? Container(
                                  width: 100,
                                  height: 34,
                                  margin: EdgeInsets.only(right: 8),
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                    color: Color(0xFFCCCCCC),
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(17)),
                                  ),
                                  child: Text(
                                    '已售罄',
                                    style: TextStyle(
                                      fontSize: 14,
                                      color: Colors.white,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                )
                              : InkWell(
                                  onTap: () {
                                    if (_kIsWeb) {
                                      downloadOrGoToApp();
                                    } else {
                                      logic.goToPreSale();
                                    }
                                  },
                                  child: Container(
                                    width: setWidth(400),
                                    height: setWidth(76),
                                    decoration: BoxDecoration(
                                      color: Color(0xff0DA460),
                                      borderRadius:
                                          BorderRadius.circular(setWidth(38)),
                                    ),
                                    alignment: Alignment.center,
                                    child: Text(
                                      '立即预订',
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 15,
                                      ),
                                    ),
                                  ),
                                ),
                    ],
                  ),
                )
              : SizedBox(),
    );
  }

  gotoHelpDesk() {
    if (SpUtil.getString('token') == null ||
        SpUtil.getString('token').isEmpty) {
      Get.toNamed(RouteConfig.mallLogin, arguments: {
        'itemNumId': logic.itemNumId,
        'styleNumId': logic.styleNumId,
        'shopId': logic.shopId,
        'typeIndex': state.typeIndex,
      }).then((value) {
        if (SpUtil.getString('token') != null &&
            SpUtil.getString('token').isNotEmpty) {
          logic.requestDetail();
        }
      });
    } else {
      if (state.keFuString.isNotEmpty) {
        var otherParams = {
          "productInfo": {},
          // "peerId": "10052439",
          "nickName": "${SpUtil.getString('empeName')}",
        };
        var clientId = '${SpUtil.getInt('empeNumId')}';
        var kefubaseUrl =
            'https://7moor.zrhsh.com/wapchat.html?fromUrl=&urlTitle=&language=ZHCN';
        kefubaseUrl = kefubaseUrl +
            '&accessId=' +
            state.keFuString +
            '&otherParams=' +
            jsonEncode(otherParams) +
            '&clientId=' +
            clientId;
        if (kIsWeb) {
          webpay(
              kefubaseUrl  );
          return;
        }
        Get.toNamed(RouteConfig.webview, arguments: {
          "url":
          kefubaseUrl,
        });
      }
    }
  }

  // 立即购买 弹框
  immediatelyBuy() {
    return showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(15),
          topRight: Radius.circular(15),
        ),
      ),
      builder: (BuildContext context) {
        bool hasSelectSpecObj =
            state.selectSpecObj != null && state.selectSpecObj.isNotEmpty;
        var store = state.goodsDetail['spec_item_detail']['store'];
        if (hasSelectSpecObj) {
          store = state.selectSpecObj['store'];
        }
        return StatefulBuilder(
          builder: (context1, state1) {
            return Container(
              height: MediaQuery.of(context).size.height / 5 * 3,
              child: Column(
                children: [
                  Container(
                    padding: EdgeInsets.all(30.w),
                    child: Row(
                      children: [
                        CachedImage(
                          path: hasSelectSpecObj
                              ? state.selectSpecObj['image_default_id']
                              : state.goodsDetail['spec_item_detail']
                                  ['image_default_id'],
                          width: 200.w,
                          height: 200.w,
                        ),
                        SizedBox(
                          width: 30.w,
                        ),
                        Container(
                          height: 200.w,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              SizedBox(height: 10.w),
                              Text(
                                '￥${logic.getBottomMoney()['priceStr'] == "0" ? "无货" : logic.getBottomMoney()['priceStr']}',
                                style: TextStyle(
                                  color: Colors.red,
                                  fontSize: 40.sp,
                                ),
                              ),
                              SizedBox(
                                height: 10.w,
                              ),
                              if (state.goodsDetail['fresh_type'] != 8)
                                Text(
                                  '库存：${logic.getBottomMoney()['priceStr'] == "0" ? "无货" : store ~/ 1}',
                                  style: TextStyle(color: Colors.grey[400]),
                                ),
                              SizedBox(
                                height: 10.w,
                              ),
                              if (state.specName.isNotEmpty)
                                Container(
                                  width: 400.w,
                                  child: Text(
                                    '已选择：${state.specName}',
                                    style: TextStyle(
                                      color: Colors.grey[400],
                                    ),
                                    maxLines: 2,
                                  ),
                                ),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  YpLine(
                    color: Colors.grey[400],
                  ),
                  SizedBox(height: 30.w),
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 30.w),
                      child: ListView.builder(
                        itemCount: state.specificationParametersList.length,
                        shrinkWrap: true,
                        itemBuilder: (itemContext, index) {
                          // if (index == state.specificationParametersList.length) {
                          //   return;
                          // }
                          Map mapIndex =
                              state.specificationParametersList[index];

                          /// 每个子规格的信息
                          List listIndex = mapIndex['spec_values'];
                          return Container(
                            width: setWidth(750),
                            padding: EdgeInsets.only(bottom: 20.w),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  mapIndex['spec_name'],
                                  style: TextStyle(
                                    color: Color(0xff333333),
                                    fontSize: 13,
                                  ),
                                ),
                                SizedBox(height: 15.w),
                                Wrap(
                                  direction: Axis.horizontal,
                                  runSpacing: 15.w,
                                  spacing: 10.w,
                                  children: listIndex
                                      .asMap()
                                      .map((key, value) {
                                        String specKey =
                                            state.ecStyleNumIdList.join("_");
                                        var data = state.spec_item[specKey];

                                        /// 规格项
                                        Map dataMap = listIndex[key];

                                        //// listview index , spec--key
                                        ///
                                        /// state.specificationParametersList[index][key]
                                        bool isChoose =
                                            state.chooseSpecificationsList[
                                                    index]['spec_value'] ==
                                                dataMap['spec_value'];

                                        String str = "";
                                        Map spec =
                                            state.specificationParameters;
                                        List tmpList = spec.keys.toList();


                                        if (isChoose) {
                                          // print(
                                          //     "state.goodsDetail=${dataMap['spec_value']}");

                                          if (state.chooseSpecificationsList !=
                                                  null &&
                                              state.chooseSpecificationsList
                                                      .length >
                                                  0) {
                                            // toast("当前规格无货");
                                            // } else {
                                            String _spec = '';
                                            state.chooseSpecificationsList
                                                .forEach((element) {
                                              _spec = _spec +
                                                  element['spec_value']
                                                      .toString() +
                                                  ' ';
                                            });
                                            state.specName = _spec;
                                            // print(
                                            //     '=====>>>>>>>ecStyleNumIdList=${data['item_name']}');
                                          } else {
                                            state.specName = data['item_name'];
                                          }
                                        }

                                        return MapEntry(
                                          key,
                                          Row(
                                            mainAxisSize: MainAxisSize.min,
                                            children: [
                                              GestureDetector(
                                                onTap: () {
                                                  // if (isChoose) return;
                                                  print(
                                                      'specKey:${specKey} +++++++++   index = $index    $dataMap');
                                                  state.chooseSpecificationsList[
                                                      index] = dataMap;
                                                  state.ec_style_num_id =
                                                      dataMap['spec_value_id'];
                                                  state.ecStyleNumIdList[
                                                          index] =
                                                      dataMap['spec_value_id'];
                                                  var specId = state
                                                      .ecStyleNumIdList
                                                      .join(
                                                          "_"); //     dataMap['spec_value_id'];
                                                  var specObj = state
                                                      .spec_item['$specId'];
                                                  state.selectSpecObj = specObj;
                                                  print(
                                                      ">>>>>>>ecStyleNumIdList=${state.ecStyleNumIdList}=state.chooseSpecificationsList=${state.chooseSpecificationsList}====$isChoose");

                                                  state1(() {
                                                    logic.specificationChoose();
                                                  });
                                                },
                                                child: Container(
                                                  padding: EdgeInsets.symmetric(
                                                      horizontal: 15.w),
                                                  alignment: Alignment.center,
                                                  height: 40.w,
                                                  decoration: BoxDecoration(
                                                    border: Border.all(
                                                      color: isChoose
                                                          ? Colors.red
                                                              .withOpacity(0.6)
                                                          : Color(0xffeeeeee),
                                                      width: 1.w,
                                                    ),
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            setWidth(20.w)),
                                                  ),
                                                  child: Text(
                                                    dataMap['spec_value'],
                                                    style: TextStyle(
                                                      color: isChoose
                                                          ? Colors.red
                                                              .withOpacity(0.6)
                                                          : Color(0xff333333),
                                                      fontSize: 13,
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        );
                                      })
                                      .values
                                      .toList(),
                                ),
                              ],
                            ),
                          );
                        },
                      ),
                    ),
                  ),
                  if (state.goodsDetail['fresh_type'] != 8)
                    YpLine(
                      color: Colors.grey[400],
                    ),
                  SizedBox(height: 30.w),
                  if (state.goodsDetail['fresh_type'] != 8)
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 30.w),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("数量"),
                          Row(
                            children: [
                              GestureDetector(
                                onTap: () {
                                  state1(() {
                                    logic.minusNum();
                                  });
                                },
                                child: Container(
                                  width: 32.0,
                                  alignment: Alignment.center,
                                  child: Image.asset(
                                    "assets/images/reduce.png",
                                    width: 45.w,
                                  ), // 设计图
                                ),
                              ),
                              Container(
                                width: 0.5,
                                color: Colors.grey,
                              ),
                              Container(
                                width: 62.0,
                                alignment: Alignment.center,
                                child: Text(
                                  state.num.toString(),
                                  maxLines: 1,
                                  style: TextStyle(
                                    fontSize: 20.0,
                                    color: Colors.black,
                                  ),
                                ),
                              ),
                              Container(
                                width: 0.5,
                                color: Colors.grey,
                              ),
                              GestureDetector(
                                onTap: () {
                                  state1(() {
                                    logic.addNum();
                                  });
                                },
                                child: Container(
                                  width: 32.0,
                                  alignment: Alignment.center,
                                  child: Image.asset(
                                    "assets/images/plus.png",
                                    width: 45.w,
                                  ), // 设计图
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  if (state.goodsDetail['fresh_type'] != 8)
                    SizedBox(height: 50.w),
                  state.deliveryType == 0
                      ? Container(
                          child: _overDeliveryView(),
                        )
                      : state.typeIndex == 0
                          ? !_kIsWeb
                              ? Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    if (state.goodsDetail['fresh_type'] != 8)
                                      GestureDetector(
                                        child: Container(
                                          decoration: BoxDecoration(
                                            color: Colors.black,
                                            borderRadius: BorderRadius.only(
                                              topLeft: Radius.circular(50.w),
                                              bottomLeft: Radius.circular(50.w),
                                            ),
                                          ),
                                          child: Text(
                                            '加入购物车',
                                            style:
                                                TextStyle(color: Colors.white),
                                            textAlign: TextAlign.center,
                                          ),
                                          width: 250.w,
                                          padding: EdgeInsets.only(
                                              top: 20.w, bottom: 20.w),
                                        ),
                                        onTap: () {
                                          if (SpUtil.getString('token') ==
                                                  null ||
                                              SpUtil.getString('token')
                                                  .isEmpty) {
                                            Get.toNamed(RouteConfig.mallLogin,
                                                arguments: {
                                                  'itemNumId': logic.itemNumId,
                                                  'styleNumId':
                                                      logic.styleNumId,
                                                  'shopId': logic.shopId,
                                                  'typeIndex': state.typeIndex,
                                                }).then((value) {
                                              if (SpUtil.getString('token') !=
                                                      null &&
                                                  SpUtil.getString('token')
                                                      .isNotEmpty) {
                                                logic.requestDetail();
                                              }
                                            });
                                          } else {
                                            String itemNumId = state
                                                            .goodsDetail[
                                                        'spec_item_detail'] !=
                                                    null
                                                ? state.goodsDetail[
                                                        'spec_item_detail']
                                                        ['item_num_id']
                                                    ?.toString()
                                                : '';
                                            // String ecShopNumId =
                                            //     SpUtil.getInt('storeShopNum')?.toString();
                                            // String ecShopNumId = state.goodsDetail['shop_num_id']
                                            //         ?.toString() ??
                                            //     SpUtil.getObject(Config.GET_SHOP_INFO)['shop_id']
                                            //         ?.toString();

                                            String ecShopNumId = state
                                                .shopInfos['shop_id']
                                                .toString();
                                            String styleNumId = state
                                                .goodsDetail['style_num_id']
                                                ?.toString();
                                            String ecStyleNumId = state
                                                            .goodsDetail[
                                                        'spec_item_detail'] !=
                                                    null
                                                ? state.goodsDetail[
                                                        'spec_item_detail']
                                                        ['ec_style_num_id']
                                                    ?.toString()
                                                : '';
                                            logic.requestAddGoods(
                                                ecShopNumId,
                                                itemNumId,
                                                styleNumId,
                                                ecStyleNumId);
                                            Get.back();
                                          }
                                        },
                                      ),
                                    GestureDetector(
                                      child: Container(
                                        decoration: BoxDecoration(
                                          color: Colors.deepOrange,
                                          borderRadius:
                                              state.goodsDetail['fresh_type'] ==
                                                      8
                                                  ? BorderRadius.all(
                                                      Radius.circular(50.w),
                                                    )
                                                  : BorderRadius.only(
                                                      topRight:
                                                          Radius.circular(50.w),
                                                      bottomRight:
                                                          Radius.circular(50.w),
                                                    ),
                                        ),
                                        child: Text(
                                          '立即购买',
                                          style: TextStyle(color: Colors.white),
                                          textAlign: TextAlign.center,
                                        ),
                                        width: 250.w,
                                        padding: EdgeInsets.only(
                                            top: 20.w, bottom: 20.w),
                                      ),
                                      onTap: () {
                                        Navigator.of(context).pop();
                                        logic.goTopay();
                                      },
                                    ),
                                  ],
                                )
                              : GestureDetector(
                                  child: Container(
                                    decoration: BoxDecoration(
                                      color: Colors.deepOrange,
                                      borderRadius: BorderRadius.circular(50.w),
                                    ),
                                    child: Text(
                                      '立即购买',
                                      style: TextStyle(color: Colors.white),
                                      textAlign: TextAlign.center,
                                    ),
                                    width: 250.w,
                                    padding: EdgeInsets.only(
                                        top: 20.w, bottom: 20.w),
                                  ),
                                  onTap: () {
                                    /// 跳转到app失败 进入下载页或者提示系统浏览器打开
                                    downloadOrGoToApp();
                                  },
                                )
                          : state.typeIndex == 1
                              ? InkWell(
                                  onTap: () {
                                    if (_kIsWeb) {
                                      /// 跳转到app失败 进入下载页或者提示系统浏览器打开
                                      downloadOrGoToApp();
                                    } else {
                                      Navigator.of(Get.context).pop();
                                      logic.goToPreSale();
                                    }
                                  },
                                  child: Container(
                                    height: setWidth(76),
                                    decoration: BoxDecoration(
                                      color: Color(0xff0DA460),
                                      borderRadius: BorderRadius.circular(50.w),
                                    ),
                                    width: 400.w,
                                    padding: EdgeInsets.only(
                                        top: 20.w, bottom: 20.w),
                                    alignment: Alignment.center,
                                    child: Text(
                                      '立即预订',
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 15,
                                      ),
                                    ),
                                  ),
                                )

                              : SizedBox(),
                  SizedBox(
                    height: ScreenUtil().bottomBarHeight + 10,
                  ),
                ],
              ),
            );
          },
        );
      },
    );
  }

  // 导航
  Widget _pageTitle() {
    return Container(
      color: Colors.black12,
      width: MediaQuery.of(context).size.width,
      height: MediaQueryData.fromWindow(window).padding.top + 47,
      padding: EdgeInsets.only(top: 20),
      child: Stack(
        children: [
          Align(
            alignment: Alignment.bottomLeft,
            child: Container(
              key: _titleHeightKey,
              width: 1,
              height: 1,
              color: Colors.transparent,
            ),
          ),
          _kIsWeb
              ? SizedBox()
              : GestureDetector(
                  onTap: () {
                    if (Get.arguments != null) {
                      Navigator.pop(context);
                    } else {
                      Get.offAllNamed(RouteConfig.main);
                    }
                  },
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Padding(
                      padding: const EdgeInsets.only(left: 12),
                      child: Image.asset(
                        'assets/images/arrow_back.png',
                        width: 18,
                        height: 18,
                      ),
                    ),
                  ),
                ),
          Align(
            alignment: Alignment.center,
            child: TabBar(
              isScrollable: true,
              controller: state.pageTitleTabController,
              tabs: <Widget>[
                Tab(text: "商品"),
                Tab(text: "评价"),
                Tab(text: "图文"),
              ],
              indicatorColor: Config.mainColor,
              onTap: (int index) {
                switch (index) {
                  case 0:
                    _scrollController.animateTo(
                      0,
                      duration: const Duration(milliseconds: 300),
                      curve: Curves.fastLinearToSlowEaseIn,
                    );
                    break;
                  case 1:
                    if (_commentLayoutOffsetY != null) {
                      _scrollController.animateTo(
                        _commentLayoutOffsetY,
                        duration: const Duration(milliseconds: 300),
                        curve: Curves.linearToEaseOut,
                      );
                    }
                    break;
                  case 2:
                    if (_richContentLayoutOffsetY != null) {
                      _scrollController.animateTo(
                        _richContentLayoutOffsetY,
                        duration: const Duration(milliseconds: 300),
                        curve: Curves.linearToEaseOut,
                      );
                    }
                    break;
                  default:
                    break;
                }
              },
            ),
          ),
        ],
      ),
    );
  }

  // 轮播图
  Widget _banner() {
    String imagesString = state.goodsDetail['list_images'];
    String videoString = state.goodsDetail['list_video'];
    // print('------商品宣传图片--------');
    // print(videoString);
    List<String> images = [];
    List<String> videos = [];
    List<String> swiperItems = [];
    List<String> videoFormats = [
      'avi',
      'AVI',
      'wmv',
      'WMV',
      'mp4',
      'MP4',
      'mkv',
      'MKV',
      'flv',
      'FLV'
    ];
    if (imagesString != null && imagesString.isNotEmpty) {
      images = imagesString.split(',');
    }
    if (videoString != null && videoString.isNotEmpty) {
      videos = videoString.split(',');
    }
    swiperItems = videos.length > 0 ? videos + images : images;
    // print(swiperItems[0].substring(swiperItems[0].length - 3));
    if ((images == null || images.isEmpty) &&
        (videos == null || videos.isEmpty)) {
      return Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.width,
        child: Image.asset(
          'assets/images/defaultAvatar_image.png',
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.width,
          fit: BoxFit.fill,
        ),
      );
    }
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.width,
      child: Swiper(
        autoplay: false,
        itemCount: swiperItems.length,
        itemBuilder: (context, index) {
          return Container(
              // child: Image.network(
              //   images[index],
              //   width: MediaQuery.of(context).size.width,
              //   height: MediaQuery.of(context).size.width,
              //   fit: BoxFit.fill,
              // ),
              // swiperItems[index].indexOf('.mp4') != -1
              child: videoFormats.indexOf(swiperItems[index]
                          .substring(swiperItems[index].length - 3)) !=
                      -1
                  ? VideoPlayerPlus(
                      VideoPlayerController.network(swiperItems[index]),
                    )
                  : InkWell(
                      onTap: () async {
                        Get.to(goodsPhotoGalleryPage(
                          images,
                          currentIndex: index - videos.length,
                        ));
                      },
                      child: CachedImage(
                        path: swiperItems[index],
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.width,
                        scale: BoxFit.fill,
                      ),
                    ));
        },
        pagination: SwiperPagination(
            builder: DotSwiperPaginationBuilder(activeColor: Config.mainColor)),
      ),
    );
  }

  final StopWatchTimer _stopWatchTimerDown = StopWatchTimer(
    mode: StopWatchMode.countDown,
    presetMillisecond: StopWatchTimer.getMilliSecFromSecond(0),
    // onChange: (value) => print('onChange $value'),
    // onChangeRawSecond: (value) => print('onChangeRawSecond $value'),
    // onChangeRawMinute: (value) => print('onChangeRawMinute $value'),
    onEnded: () {
      print('onEnded');
    },
  );
  //时间格式化，根据总秒数转换为对应的 hh:mm:ss 格式
  Map constructTime(int mss) {
    int days = (mss / (60 * 60 * 24)).floor();
    int hours = ((mss % (60 * 60 * 24)) / (60 * 60)).floor();
    int minutes = ((mss % (60 * 60)) / 60).floor();
    int seconds = (mss % 60).floor();
    print(days.toString() +
        "天" +
        hours.toString() +
        "小时" +
        minutes.toString() +
        "分钟" +
        seconds.toString() +
        "秒");
    return {
      'hours': hours,
      "minutes": minutes,
      'seconds': seconds,
      'days': days,
    };
  }

  String _skDaysNo = '';
  bool hasGotNo = false;
  Widget _secondsKillRowNo() {
    Future.delayed(Duration(milliseconds: 1000), () {
      Timer.periodic(Duration(seconds: 1), (timer) {
        if (hasGotNo == false && state.goodsDetail['spec_item_detail'] != null) {
          hasGotNo = true;
          timer.cancel();
          Map timeMap = constructTime((state.goodsDetail['spec_item_detail']
          ['to_start_time'] / 1000).floor());
          _stopWatchTimerDown.setPresetHoursTime(timeMap['hours']);
          _stopWatchTimerDown.setPresetMinuteTime(timeMap['minutes']);
          _stopWatchTimerDown.setPresetSecondTime(timeMap['seconds']);
          setState(() {
            _stopWatchTimerDown.onExecute.add(StopWatchExecute.start);
            if (timeMap['days'] > 0) {
              _skDaysNo = '${timeMap['days']}天';
            } else {
              _skDaysNo = '';
            }
          });
          print('_skDays:$_skDaysNo');
        }
      });
    });
    return Container(
      color: Colors.deepOrangeAccent,
      padding: EdgeInsets.symmetric(horizontal: 15),
      height: 50,
      child: Row(
        children: [
          Expanded(
            child: Text(
              '限时秒杀  未开始：',
              style: TextStyle(fontSize: 14, color: Colors.white),
            ),
          ),
          Text(
            '距开始：',
            style: TextStyle(fontSize: 14, color: Colors.white),
          ),
          Container(
            alignment: Alignment.centerLeft,
            child: StreamBuilder<int>(
              stream: _stopWatchTimerDown.rawTime,
              initialData: _stopWatchTimerDown.rawTime.value,
              builder: (context, snap) {
                final value = snap.data;
                final displayTime = StopWatchTimer.getDisplayTime(
                  value,
                  hours: true,
                  milliSecond: false,
                  hoursRightBreak: '小时',
                  minuteRightBreak: '分',
                  secondRightBreak: '秒',
                );
                // print('displayTime:$displayTime');
                return Container(
                  // padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
                  child: Text(
                    '$_skDaysNo$displayTime秒',
                    style: TextStyle(fontSize: 12, color: Colors.white),
                  ),
                );
              },
            ),
          ),
        ],
      ),
    );
  }

  String _skDays = '';
  bool hasGot = false;
  Widget _secondsKillRow() {
    Future.delayed(Duration(milliseconds: 1000), () {
      Timer.periodic(Duration(seconds: 1), (timer) {
        if (hasGot == false && state.goodsDetail['spec_item_detail'] != null) {
          hasGot = true;
          timer.cancel();
          Map timeMap = constructTime((state.goodsDetail['spec_item_detail']
                      ['seckill_countdown_time'] /
                  1000)
              .floor());
          _stopWatchTimerDown.setPresetHoursTime(timeMap['hours']);
          _stopWatchTimerDown.setPresetMinuteTime(timeMap['minutes']);
          _stopWatchTimerDown.setPresetSecondTime(timeMap['seconds']);
          setState(() {
            _stopWatchTimerDown.onExecute.add(StopWatchExecute.start);
            if (timeMap['days'] > 0) {
              _skDays = '${timeMap['days']}天';
            } else {
              _skDays = '';
            }
          });
          print('_skDays:$_skDays');
        }
      });
    });
    return Container(
      color: Colors.deepOrangeAccent,
      height: 50,
      child: Row(
        children: [
          Expanded(
            child: Row(children: [
              SizedBox(width: 10),
              Text(
                '限时秒杀',
                style: TextStyle(fontSize: 14, color: Colors.white),
              ),
              Text(
                '  秒杀中...',
                style: TextStyle(fontSize: 12, color: Colors.white),
              ),
            ]),
            flex: 1,
          ),
          // Text(  '秒杀中...             距结束：',  style: TextStyle(fontSize: 12, color: Colors.white),),
          Expanded(
            child: StreamBuilder<int>(
              stream: _stopWatchTimerDown.rawTime,
              initialData: _stopWatchTimerDown.rawTime.value,
              builder: (context, snap) {
                final value = snap.data;
                final displayTime = StopWatchTimer.getDisplayTime(
                  value,
                  hours: true,
                  milliSecond: false,
                  hoursRightBreak: '小时',
                  minuteRightBreak: '分',
                  secondRightBreak: '秒',
                );
                // print('displayTime:$displayTime');
                return Container(
                  // padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
                  child: Text(
                    '距结束：$_skDays$displayTime秒',
                    style: TextStyle(fontSize: 12, color: Colors.white),
                  ),
                );
              },
            ),
            flex: 1,
          ),
        ],
      ),
    );
  }

  //标题信息
  Widget _titleAndPriceLayout() {
    String goodsTitle =
        state.goodsDetail['title'] != null ? state.goodsDetail['title'] : '';
    String price = state.goodsDetail['spec_item_detail'] != null &&
            state.goodsDetail['spec_item_detail']['price'] != null
        ? state.goodsDetail['spec_item_detail']['price'].toString()
        : '';
    String priceStr = '', oldPriceStr = '', tiShi = '';
    bool oldBool = false;
    if (state.goodsDetail['spec_item_detail']['is_seckill'] == 1) {
      // 秒杀商品
      priceStr = state.goodsDetail['spec_item_detail']['price'].toString();
      oldBool = state.goodsDetail['spec_item_detail']['mkt_price'] >
          state.goodsDetail['spec_item_detail']['price']; // 显示旧价格
      oldPriceStr =
          state.goodsDetail['spec_item_detail']['mkt_price'].toString();
    } else if (state.goodsDetail['spec_item_detail']['is_pre_sale'] == 1) {
      priceStr = state.goodsDetail['spec_item_detail']['price'].toString();
      oldBool = state.goodsDetail['spec_item_detail']['mkt_price'] >
          state.goodsDetail['spec_item_detail']['price']; // 显示旧价格
      oldPriceStr =
          state.goodsDetail['spec_item_detail']['mkt_price'].toString();
    } else {
      if (state.goodsDetail['spec_item_detail']['expect_price'] > 0) {
        priceStr =
            '${state.goodsDetail['spec_item_detail']['expect_price'].toString()}';
        tiShi = '折后';
        oldBool = state.goodsDetail['spec_item_detail']['mkt_price'] >
            state.goodsDetail['spec_item_detail']['expect_price']; // 显示旧价格
        oldPriceStr =
            state.goodsDetail['spec_item_detail']['mkt_price'].toString();
      } else {
        priceStr = state.goodsDetail['spec_item_detail']['price'].toString();
        oldBool = state.goodsDetail['spec_item_detail']['mkt_price'] >
            state.goodsDetail['spec_item_detail']['price']; // 显示旧价格
        oldPriceStr = state.goodsDetail['spec_item_detail']['mkt_price']
            .toString(); //market_price
      }
    }

    String preSaleDes = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['pre_sale_des']
        : '';

    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 10),
      child: state.typeIndex == 0
          ? Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '$goodsTitle',
                  maxLines: 3,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                      color: Colors.black),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      RichText(
                        text: TextSpan(
                          children: [
                            TextSpan(
                                text: tiShi + '¥',
                                style: TextStyle(
                                    fontSize: 12, color: Config.mainColor)),
                            TextSpan(
                                text: priceStr,
                                style: TextStyle(
                                    fontSize: 16,
                                    fontWeight: FontWeight.bold,
                                    color: Config.mainColor)),
                            WidgetSpan(child: SizedBox(width: setWidth(8))),
                            oldBool
                                ? TextSpan(
                                    text: '￥$oldPriceStr',
                                    style: TextStyle(
                                      fontSize: 11,
                                      color: Color(0xff999999),
                                      decoration: TextDecoration.lineThrough,
                                    ),
                                  )
                                : WidgetSpan(child: SizedBox()),
                            // WidgetSpan(child: SizedBox(width: setWidth(8))),
                            // TextSpan(
                            //   text: state.goodsDetail['spec_item_detail']
                            //               ['commission_amount'] >
                            //           0
                            //       ? '赚${state.goodsDetail['spec_item_detail']['commission_amount']}'
                            //       : '',
                            //   style: TextStyle(
                            //     color: Color(0xffdd2f3e),
                            //     fontSize: 10,
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                      if (!_kIsWeb)
                        GestureDetector(
                          onTap: () {
                            if (SpUtil.getString('token') == null ||
                                SpUtil.getString('token').isEmpty) {
                              Get.toNamed(RouteConfig.mallLogin, arguments: {
                                'itemNumId': logic.itemNumId,
                                'styleNumId': logic.styleNumId,
                                'shopId': logic.shopId,
                                'typeIndex': state.typeIndex,
                              }).then((value) {
                                if (SpUtil.getString('token') != null &&
                                    SpUtil.getString('token').isNotEmpty) {
                                  logic.requestDetail();
                                }
                              });
                            } else {
                              num store = (state.goodsDetail != null &&
                                      state.goodsDetail['spec_item_detail'] !=
                                          null)
                                  ? state.goodsDetail['spec_item_detail']
                                      ['store']
                                  : 0;
                              if (store <= 0) {
                                toast('该商品已没有库存，不允许分享');
                              } else {
                                showShareBottomSheet(context);
                              }
                            }
                          },
                          child: Align(
                            alignment: Alignment.centerRight,
                            child: Padding(
                              padding: EdgeInsets.only(
                                left: 15,
                                top: 10,
                                bottom: 10,
                              ),
                              child: Image.asset(
                                'assets/images/share.png',
                                width: 18,
                                height: 18,
                                color: Colors.red,
                              ),
                            ),
                          ),
                        ),
                    ],
                  ),
                ),
                state.goodsDetail['is_show_sold_qty'] == 0
                    ? Text('')
                    : Text(
                        '已售${(state.goodsDetail['sold_quantity'] ?? 0) ~/ 1}件',
                        style: TextStyle(
                          color: Color(0xff999999),
                          fontSize: 12,
                        ),
                      ),
              ],
            )
          : state.typeIndex == 1
              ? Column(
                  children: [
                    Container(
                      height: setWidth(120),
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.centerLeft,
                          end: Alignment.centerRight,
                          colors: [
                            Color(0xff09B266),
                            Color(0xff0E8851),
                          ],
                        ),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '预售价',
                                style: TextStyle(
                                    color: Colors.white, fontSize: 12),
                              ),
                              Text.rich(
                                TextSpan(
                                  children: [
                                    TextSpan(
                                      text: '¥',
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 12,
                                      ),
                                    ),
                                    TextSpan(
                                      text: priceStr,
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 28,
                                      ),
                                    ),
                                    WidgetSpan(
                                        child: SizedBox(
                                      width: setWidth(14),
                                    )),
                                    // TextSpan(
                                    //   text: '原价:¥${ oldPriceStr<priceStr?priceStr:oldPriceStr}',
                                    //   style: TextStyle(
                                    //     color: Colors.white,
                                    //     fontSize: 12,
                                    //     decoration: TextDecoration.lineThrough,
                                    //   ),
                                    // ),
                                  ],
                                ),
                              ),
                            ],
                          ),

                          _kIsWeb
                              ? SizedBox()
                              : GestureDetector(
                                  onTap: () {
                                    if (SpUtil.getString('token') == null ||
                                        SpUtil.getString('token').isEmpty) {
                                      Get.toNamed(RouteConfig.mallLogin,
                                          arguments: {
                                            'itemNumId': logic.itemNumId,
                                            'styleNumId': logic.styleNumId,
                                            'shopId': logic.shopId,
                                            'typeIndex': state.typeIndex,
                                          }).then((value) {
                                        if (SpUtil.getString('token') != null &&
                                            SpUtil.getString('token')
                                                .isNotEmpty) {
                                          logic.requestDetail();
                                        }
                                      });
                                    } else {
                                      num store = (state.goodsDetail != null &&
                                              state.goodsDetail[
                                                      'spec_item_detail'] !=
                                                  null)
                                          ? state.goodsDetail[
                                              'spec_item_detail']['store']
                                          : 0;
                                      if (store <= 0) {
                                        toast('该商品已没有库存，不允许分享');
                                      } else {
                                        showShareBottomSheet(context);
                                      }
                                    }
                                  },
                                  child: Align(
                                    alignment: Alignment.centerRight,
                                    child: Padding(
                                      padding: EdgeInsets.only(
                                        left: 15,
                                        top: 10,
                                        bottom: 10,
                                      ),
                                      child: Icon(
                                        Icons.share,
                                        color: const Color(0xffffffff),
                                      ),
                                    ),
                                  ),
                                ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: setWidth(22)),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(
                              top: setWidth(24),
                              bottom: setWidth(16),
                            ),
                            child: Text(
                              '$goodsTitle',
                              style: TextStyle(
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                                fontSize: 16,
                              ),
                            ),
                          ),

                          SizedBox(
                            height: setWidth(16),
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Text(
                                  preSaleDes ?? '',
                                  style: TextStyle(
                                    color: Color(0xff0F0F0F),
                                    fontSize: 12,
                                  ),
                                ),
                              ),
                              SizedBox(
                                width: setWidth(20),
                              ),
                              state.goodsDetail['is_show_sold_qty'] == 0
                                  ? Text('')
                                  : Text(
                                      '已售${(state.goodsDetail['sold_quantity'] ?? 0) ~/ 1}件',
                                      style: TextStyle(
                                        color: Color(0xffA3A3A3),
                                        fontSize: 10,
                                      ),
                                    ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                )
              : SizedBox(),
    );
  }

  //分隔控件
  Widget _divider(double height) {
    return Container(
      width: double.infinity,
      height: height,
      color: const Color(0xFFF3F4F6),
    );
  }

  // 促销
  Widget _promotionWidget() {
    var specItemDetail = state.goodsDetail['spec_item_detail'];
    var hasExchange = specItemDetail['integral_exchange_desc'] != null; // 积分优惠
    var hasLimit = specItemDetail['integral_limit_desc'] != null; // 限购
    var hasSecKill = specItemDetail['seckill_desc'] != null; // 秒杀
    bool show = state.promotionalInformationList.length > 0 &&
            state.promotionalInformationList[0]['corner_detail'] != "按不限购元结算" ||
        hasExchange ||
        hasLimit ||
        hasSecKill;
    return show // 促销策略
        ? Container(
            padding: EdgeInsets.symmetric(horizontal: 10),
            child: Column(
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: setWidth(80),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '促销',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 14,
                          height: 1.8, //1倍行高
                        ),
                      ),
                    ),
                    Expanded(
                      /*
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      padding: EdgeInsets.only(
                        top: setWidth(32),
                        bottom: setWidth(24),
                      ),
                      child: RichText(
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.left,
                        text: TextSpan(
                          children: [
                            WidgetSpan(
                              child: Container(
                                width: setWidth(56),
                                height: setWidth(28),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Color(0x1aEF2F45),
                                  border: Border.all(
                                    color: Color(0xffEF2F45),
                                    width: setWidth(1),
                                  ),
                                  borderRadius: BorderRadius.circular(setWidth(3)),
                                ),
                                child: Text(
                                  '满减',
                                  style: TextStyle(
                                    color: Color(0xffEF2F45),
                                    fontSize: 10,
                                  ),
                                ),
                              ),
                            ),
                            WidgetSpan(
                              child: SizedBox(width: setWidth(16)),
                            ),
                            TextSpan(
                              text: '满199元减100元满199元减100元满199元减100元满199元减100元满199元减100元',
                              style: TextStyle(
                                color: Color(0xffEF2F45),
                                fontSize: 14,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Divider(
                      color: Color(0xffEFEFEF),
                      height: 1,
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                          top: setWidth(26),
                          bottom: setWidth(30)
                      ),
                      child: RichText(
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.left,
                        text: TextSpan(
                          children: [
                            WidgetSpan(
                              child: Container(
                                width: setWidth(56),
                                height: setWidth(28),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Color(0x1aEF2F45),
                                  border: Border.all(
                                    color: Color(0xffEF2F45),
                                    width: setWidth(1),
                                  ),
                                  borderRadius: BorderRadius.circular(setWidth(3)),
                                ),
                                child: Text(
                                  '秒杀',
                                  style: TextStyle(
                                    color: Color(0xffEF2F45),
                                    fontSize: 10,
                                  ),
                                ),
                              ),
                            ),
                            WidgetSpan(
                              child: SizedBox(width: setWidth(16)),
                            ),
                            TextSpan(
                              text: '每人每天购买不超过3件',
                              style: TextStyle(
                                color: Color(0xffEF2F45),
                                fontSize: 14,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Divider(
                      color: Color(0xffEFEFEF),
                      height: 1,
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                        top: setWidth(28),
                        bottom: setWidth(28),
                      ),
                      child: RichText(
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.left,
                        text: TextSpan(
                          children: [
                            WidgetSpan(
                              child: Container(
                                width: setWidth(100),
                                height: setWidth(28),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  color: Color(0x1aEF2F45),
                                  border: Border.all(
                                    color: Color(0xffEF2F45),
                                    width: setWidth(1),
                                  ),
                                  borderRadius: BorderRadius.circular(setWidth(3)),
                                ),
                                child: Text(
                                  '积分优惠',
                                  style: TextStyle(
                                    color: Color(0xffEF2F45),
                                    fontSize: 10,
                                  ),
                                ),
                              ),
                            ),
                            WidgetSpan(
                              child: SizedBox(width: setWidth(16)),
                            ),
                            TextSpan(
                              text: '使用20积分可享受优惠价39元',
                              style: TextStyle(
                                color: Color(0xffEF2F45),
                                fontSize: 14,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
                */
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            ...state.promotionalInformationList
                                .asMap()
                                .map((key, value) {
                                  return MapEntry(
                                    key,
                                    Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Padding(
                                          padding: EdgeInsets.only(
                                            top: setWidth(10),
                                            bottom: setWidth(24),
                                          ),
                                          child: RichText(
                                            textAlign: TextAlign.left,
                                            text: TextSpan(
                                              children: [
                                                WidgetSpan(
                                                  child: Row(
                                                    mainAxisSize:
                                                        MainAxisSize.min,
                                                    children: [
                                                      Container(
                                                        padding: EdgeInsets
                                                            .symmetric(
                                                                horizontal:
                                                                    setWidth(
                                                                        5)),
                                                        height: setWidth(28),
                                                        alignment:
                                                            Alignment.center,
                                                        decoration:
                                                            BoxDecoration(
                                                          color: (value['tag_fgcolor'] ==
                                                                      null ||
                                                                  value['tag_fgcolor'] ==
                                                                      '')
                                                              ? Color(
                                                                  0x1aEF2F45)
                                                              : getColorFromHex(
                                                                  '${value['tag_fgcolor']}'),
                                                          border: Border.all(
                                                            color: (value['word_color'] ==
                                                                        null ||
                                                                    value['word_color'] ==
                                                                        '')
                                                                ? Color(
                                                                    0xffEF2F45)
                                                                : getColorFromHex(
                                                                    '${value['word_color']}'),
                                                            width: setWidth(1),
                                                          ),
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(
                                                                      setWidth(
                                                                          3)),
                                                        ),
                                                        child: Text(
                                                          '${value['tag_name']}',
                                                          style: TextStyle(
                                                            color: (value['frame_color'] ==
                                                                        null ||
                                                                    value['frame_color'] ==
                                                                        '')
                                                                ? Color(
                                                                    0xffEF2F45)
                                                                : getColorFromHex(
                                                                    '${value['frame_color']}'),
                                                            fontSize: 10,
                                                          ),
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                                WidgetSpan(
                                                  child: SizedBox(
                                                      width: setWidth(16)),
                                                ),
                                                TextSpan(
                                                  text:
                                                      '${value['corner_detail']}',
                                                  style: TextStyle(
                                                    // color: Color(0xffFFFBF2),
                                                    color: (value['frame_color'] ==
                                                                null ||
                                                            value['frame_color'] ==
                                                                '')
                                                        ? Color(0xff333333)
                                                        : getColorFromHex(
                                                            '${value['frame_color']}'),
                                                    fontSize: 14,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                        Offstage(
                                          offstage:
                                              state.promotionalInformationList
                                                          .length -
                                                      1 ==
                                                  key,
                                          child: Divider(
                                            color: Color(0xffEFEFEF),
                                            height: 1,
                                          ),
                                        ),
                                      ],
                                    ),
                                  );
                                })
                                .values
                                .toList(),
                            hasExchange
                                ? Container(
                                    child: Row(children: [
                                    Container(
                                        child: Text('积分优惠',
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontSize: 10)),
                                        padding:
                                            EdgeInsets.symmetric(horizontal: 5),
                                        margin: EdgeInsets.only(right: 4),
                                        decoration: BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(10),
                                            color: Config.mainColor)),
                                    Text(
                                        specItemDetail[
                                            'integral_exchange_desc'],
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Config.mainColor))
                                  ]))
                                : Container(),
                            hasLimit
                                ? Container(
                                    child: Row(children: [
                                    Container(
                                        child: Text('限购',
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontSize: 10)),
                                        padding:
                                            EdgeInsets.symmetric(horizontal: 5),
                                        margin: EdgeInsets.only(right: 4),
                                        decoration: BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(10),
                                            color: Config.mainColor)),
                                    Text(specItemDetail['integral_limit_desc'],
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Config.mainColor))
                                  ]))
                                : Container(),
                            hasSecKill
                                ? Container(
                                    width: 600.w,
                                    child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                            child: Text('秒杀',
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 10)),
                                            padding: EdgeInsets.symmetric(
                                                horizontal: 5),
                                            margin: EdgeInsets.only(right: 4),
                                            decoration: BoxDecoration(
                                                borderRadius:
                                                    BorderRadius.circular(10),
                                                color: Config.mainColor)),
                                        Expanded(
                                          child: Text(
                                            specItemDetail['seckill_desc'],
                                            style: TextStyle(
                                              fontSize: 14,
                                              color: Config.mainColor,
                                              height: 1,
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  )
                                : Container()
                          ]),
                    ),
                  ],
                ),
                Divider(
                  color: Color(0xffEFEFEF),
                  height: 1,
                ),
              ],
            ),
          )
        : Container();
  }

  // 领券
  Widget _couponsLayout() {
    if (state.availableCoupons == null ||
        state.availableCoupons['card_tickets'] == null) {
      return Container();
    }
    List couponList = state.availableCoupons['card_tickets'];
    if (couponList == null || couponList.isEmpty) {
      return Container();
    }
    StringBuffer couponContent = StringBuffer();
    for (int index = 0; index < couponList.length; index++) {
      var coupon = couponList[index];
      couponContent.write(coupon['title']);
      if (index < couponList.length - 1) {
        couponContent.write(',');
      }
    }

    return GestureDetector(
      onTap: () {
        logic.requestGotCoupons(() {
          showCouponDialog();
        });
      },
      child: Container(
        padding: EdgeInsets.only(left: 10, top: 0, right: 10, bottom: 0),
        child: Row(
          children: [
            Text('领券'),
            Expanded(
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Text(
                  couponContent.toString(),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(fontSize: 14, color: Config.mainColor),
                ),
              ),
            ),
            IconButton(
                onPressed: () {
                  logic.requestGotCoupons(() {
                    showCouponDialog();
                  });
                },
                icon: Image.asset(
                  'assets/images/more.png',
                  width: 20,
                  height: 6,
                )),
          ],
        ),
      ),
    );
  }

  String listToString(List list) {
    if (list == null) {
      return state.goodsDetail['title'];
    }
    if (list.length == 0) {
      return state.goodsDetail['title'];
    }
    String result;
    list.forEach((string) => {
          if (result == null)
            result = string['spec_value']
          else
            result = '$result，${string['spec_value']}'
        });
    if (result == null) result = '';
    return result.toString();
  }

  ///活动
  Widget _surpriseTaskRow() {
    return InkWell(
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
        color: Colors.black12,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [

            Container(
              // color:Colors.deepOrangeAccent,
              width: setWidth(80),
              height: 20,
              alignment: Alignment.centerLeft,
              child: Text(
                '活动',
                style: TextStyle(
                  color: Color(0xff666666),
                  fontSize: 14,
                  height: 1.5, //1倍行高
                ),
              ),
            ),

            Expanded(
              child: Container(
                height: 20,
                // color:Colors.green,
                alignment: Alignment.topLeft,
                child: ListView.builder(
                    itemCount: state.ConsumeList.length,
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    scrollDirection: Axis.horizontal,
                    itemBuilder: (context, index) => Container(
                          // margin: EdgeInsets.fromLTRB(12, 8, 12, 10),
                          // padding: EdgeInsets.only(bottom: 16),
                          // decoration: EsDecoration.BoxShadowWithRadius,
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                // Container(
                                //   alignment: Alignment.center,
                                //   color:Colors.deepOrangeAccent,
                                //   padding: const EdgeInsets.only(
                                //       top: 0, right: 3, left: 3,bottom:0, ),
                                //   child: Text(
                                //       state.ConsumeList[index]['award_type_name']
                                //           .toString(),
                                //       style: TextStyle(
                                //           color: Colors.white,
                                //         fontSize: 14,
                                //         //height: 1.5,
                                //       )),
                                // ),
                                Container(
                                    child: Text(
                                        state.ConsumeList[index]
                                                ['award_type_name']
                                            .toString(),
                                        style: TextStyle(
                                            color: Colors.white, fontSize: 10)),
                                    padding:
                                        EdgeInsets.symmetric(horizontal: 5),
                                    margin: EdgeInsets.only(right: 4),
                                    decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Config.mainColor)),
                                SizedBox(height: 8, width: 8),
                                Container(
                                  // padding: const EdgeInsets.only(
                                  //     top: 16, right: 55, left: 12),
                                  child: Text(
                                      state.ConsumeList[index]['activity_name']
                                          .toString(),
                                      style: TextStyle(
                                          // color: EsColors.Title,
                                          // fontSize: EsSizes.LG,
                                          // fontWeight: EsFontWeights.Medium,
                                          )),
                                ),
                                SizedBox(height: 8, width: 8),
                              ],
                            ),
                          ),
                        )),
              ),
              flex: 1,
            ),
            Container(
              child: Text(
                '>',
                style: TextStyle(
                  color: Color(0xff666666),
                  fontSize: 16,
                  height: 1.5, //1倍行高
                ),
              ),
              alignment: Alignment.centerRight,
            ),
            SizedBox(height: 8, width: 10),
          ],
        ),
      ),
      onTap: () {
        Get.toNamed(RouteConfig.consumeGift);
      },
    );
  }

  // 配送方式
  Widget _distributionMannerWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: setWidth(28)),
      child: Row(
        children: [
          Text(
            '配送方式',
            style: TextStyle(
              color: Color(0xff666666),
              fontSize: 14,
            ),
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                '门店自提、快递',
                style: TextStyle(
                  color: Color(0xff222222),
                  fontSize: 15,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  // 已选
  Widget _selectedWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10),
      child: Row(
        children: [
          Text(
            '已选',
            style: TextStyle(
              color: Color(0xff666666),
              fontSize: 14,
            ),
          ),
          Expanded(
            child: Padding(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                // '22超大风量+挥手智控',
                listToString(state.chooseSpecificationsList) == ''
                    ? 'X${state.num}/${state.goodsDetail['unit_name']}'
                    : '${listToString(state.chooseSpecificationsList)}，X${state.num}/${state.goodsDetail['unit_name']}',
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  color: Color(0xff222222),
                  fontSize: 14,
                ),
              ),
            ),
          ),
          IconButton(
            onPressed: () {
              if (_kIsWeb) {
                downloadOrGoToApp();
                return;
              }
              if (SpUtil.getString('token') == null ||
                  SpUtil.getString('token').isEmpty) {
                Get.toNamed(RouteConfig.mallLogin, arguments: {
                  'itemNumId': logic.itemNumId,
                  'styleNumId': logic.styleNumId,
                  'shopId': logic.shopId,
                  'typeIndex': state.typeIndex,
                }).then((value) {
                  if (SpUtil.getString('token') != null &&
                      SpUtil.getString('token').isNotEmpty) {
                    logic.requestDetail();
                  }
                });
              } else {
                immediatelyBuy();
              }
            },
            icon: Image.asset(
              'assets/images/arrow_right.png',
              width: 20,
              height: 20,
            ),
          ),
        ],
      ),
    );
  }

  // 推荐商品
  Widget _recommendGoodsModule() {
    if (state.recommendGoods == null || state.recommendGoods['lists'] == null) {
      return Container();
    }
    List list = state.recommendGoods['lists'];
    if (list == null || list.isEmpty) {
      return Container();
    }
    return Container(
      width: MediaQuery.of(context).size.width,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: const EdgeInsets.only(left: 5, right: 5),
            height: 200,
            child: ListView.builder(
              shrinkWrap: true,
              scrollDirection: Axis.horizontal,
              itemCount: list.length,
              itemBuilder: (context, index) {
                return _recommendGoodsItem(list[index]);
              },
            ),
          ),
        ],
      ),
    );
  }

  // 推荐商品 item
  Widget _recommendGoodsItem(var goods) {
    String imgUrl = goods['image_default_id'];
    String goodsName = goods['title'];
    String price1 = goods['price'].toString();
    String price2 = goods['mkt_price'].toString();
    bool soldOutBool = goods['style_store'] <= 0;

    return InkWell(
      onTap: () {
        print('！！！！！！！！！！  商品点击事件  ！！！！！！！！！！');
        print('goods = $goods');
        print('！！！！！！！！！！  商品点击事件  ！！！！！！！！！！');

        String itemNumId = goods['default_item_num_id']?.toString() ?? '';
        String styleNumId = goods['style_num_id']?.toString() ?? '';
        String shopId = goods['shop_num_id']?.toString() ?? '';
        String cat1Id = goods['cat1_id']?.toString() ?? '';
        String ecStyleNumId = goods['ec_style_num_id'].toString() ?? '';
        print('商品点击事件'
            'itemNumId = $itemNumId'
            'styleNumId = $styleNumId'
            'shopId = $shopId'
            'cat1Id = $cat1Id'
            'ecStyleNumId = $ecStyleNumId');

        Get.back();
        Get.toNamed(RouteConfig.goodsDetail, arguments: {
          'itemNumId': itemNumId,
          'styleNumId': styleNumId,
          'shopId': shopId,
          'cat1Id': cat1Id,
          'ecStyleNumId': ecStyleNumId,
          'typeIndex': goods['is_pre_sale'],
        });
      },
      child: Container(
        width: 120,
        padding: const EdgeInsets.symmetric(horizontal: 5),
        child: Column(
          children: [
            Stack(
              children: [
                CachedImage(
                  width: 110,
                  height: 110,
                  margin: EdgeInsets.zero,
                  scale: BoxFit.fill,
                  path: imgUrl,
                ),
                Positioned(
                  left: 25,
                  top: 25,
                  child: soldOutBool
                      ? Container(
                          width: 60,
                          height: 60,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Color(0xffbbbbbb).withOpacity(0.7),
                            borderRadius: BorderRadius.circular(setWidth(60)),
                          ),
                          child: Text(
                            '售罄',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15,
                            ),
                          ),
                        )
                      : SizedBox(),
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(top: 10),
              child: Text(
                goodsName,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: 12, color: Colors.black),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.only(right: 8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          RichText(
                              text: TextSpan(children: [
                            TextSpan(
                                text: '¥',
                                style: TextStyle(
                                  fontSize: 12,
                                  color: Config.mainColor,
                                )),
                            TextSpan(
                                text: price1,
                                style: TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                  color: Config.mainColor,
                                )),
                          ])),
                          Text(
                            price2,
                            style: TextStyle(
                              fontSize: 12,
                              color: const Color(0xFFCCCCCC),
                              decoration: TextDecoration.lineThrough,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  _kIsWeb || goods['fresh_type'] == 8
                      ? SizedBox()
                      : GestureDetector(
                          onTap: () {
                            if (SpUtil.getString('token') == null ||
                                SpUtil.getString('token').isEmpty) {
                              Get.toNamed(RouteConfig.mallLogin, arguments: {
                                'itemNumId': logic.itemNumId,
                                'styleNumId': logic.styleNumId,
                                'shopId': logic.shopId,
                                'typeIndex': state.typeIndex,
                              }).then((value) {
                                if (SpUtil.getString('token') != null &&
                                    SpUtil.getString('token').isNotEmpty) {
                                  logic.requestDetail();
                                }
                              });
                            } else {
                              if (!soldOutBool) {
                                String ecShopNumId =
                                    goods['shop_num_id']?.toString() ??
                                        SpUtil.getObject(
                                                Config.GET_SHOP_INFO)['shop_id']
                                            ?.toString();
                                String itemNumId =
                                    goods['default_item_num_id']?.toString();
                                String styleNumId =
                                    goods['style_num_id']?.toString();
                                String ecStyleNumId =
                                    goods['ec_style_num_id']?.toString();
                                logic.requestAddGoods(ecShopNumId, itemNumId,
                                    styleNumId, ecStyleNumId);
                              }
                            }
                          },
                          child: Image.asset(
                            'assets/images/add_shopping_cart.png',
                            width: 20,
                            height: 20,
                            color: !soldOutBool
                                ? Color(0xffEA5504)
                                : Color(0xffcccccc),
                          ),
                        )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 规格参数
  Widget _specificationParametersWidget() {
    String imagesString = '${state.goodsDetail['params']}';
    List mapData = convert.jsonDecode(imagesString);
    List childrenList = [];
    if (mapData.length > 0) {
      childrenList = mapData[0]['children'];
    }

    return childrenList.length > 0
        ? Container(
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  height: setWidth(84),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: Row(
                    children: [
                      GestureDetector(
                        onTap: () {
                          state.showProp = true;
                          logic.update();
                        },
                        child: Container(
                          width: setWidth(180),
                          child: Text(
                            '规格参数',
                            style: TextStyle(
                              color: state.showProp
                                  ? Colors.black
                                  : Color(0xff999999),
                              fontSize: 16,
                            ),
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: () {
                          state.showProp = false;
                          logic.update();
                        },
                        child: Text(
                          '售后保障',
                          style: TextStyle(
                            color: !state.showProp
                                ? Colors.black
                                : Color(0xff999999),
                            fontSize: 16,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Divider(
                  height: setWidth(1),
                  color: Color(0xffE7E7E7),
                  indent: setWidth(20),
                  endIndent: 0,
                ),
                Container(
                  padding: EdgeInsets.only(
                    left: setWidth(26),
                    top: setWidth(12),
                    right: setWidth(26),
                    bottom: setWidth(22),
                  ),
                  child: !state.showProp
                      ? Container(
                          child: state.showhou == null
                              ? Container()
                              : Column(
                                  children: [
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(250),
                                          child: Text(
                                            '是否提供安装服务:',
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          child: Text(
                                            '${state.showhou['install_service_sign'] == 1 ? '是' : '否'}',
                                            style: TextStyle(
                                              color: Color(0xff666666),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(250),
                                          child: Text(
                                            '是否提供退换货服务:',
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          child: Text(
                                            '${state.showhou['return_exchange_sign'] == 1 ? '是' : '否'}',
                                            style: TextStyle(
                                              color: Color(0xff666666),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(250),
                                          child: Text(
                                            '退换货承诺:',
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                        if (state.showhou[
                                                    'return_exchange_promise']
                                                .toString() ==
                                            "1")
                                          Expanded(
                                            child: Text(
                                              '7天无理由退货',
                                              style: TextStyle(
                                                color: Color(0xff666666),
                                                fontSize: 12,
                                                height: 1,
                                              ),
                                            ),
                                          ),
                                        if (state.showhou[
                                                    'return_exchange_promise']
                                                .toString() ==
                                            "2")
                                          Expanded(
                                            child: Text(
                                              '30天内申请换货',
                                              style: TextStyle(
                                                color: Color(0xff666666),
                                                fontSize: 12,
                                                height: 1,
                                              ),
                                            ),
                                          ),
                                        if (state.showhou[
                                                    'return_exchange_promise']
                                                .toString() ==
                                            "3")
                                          Expanded(
                                            child: Text(
                                              '7天质量问题退换货',
                                              style: TextStyle(
                                                color: Color(0xff666666),
                                                fontSize: 12,
                                                height: 1,
                                              ),
                                            ),
                                          ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(250),
                                          child: Text(
                                            '是否提供保修服务:',
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          child: Text(
                                            '${state.showhou['guarantee_sign'] == 1 ? '是' : '否'}',
                                            style: TextStyle(
                                              color: Color(0xff666666),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          width: setWidth(250),
                                          child: Text(
                                            '是否提供上门服务:',
                                            style: TextStyle(
                                              color: Color(0xff222222),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          child: Text(
                                            '${state.showhou['after_sales_door_sign'] == 1 ? '是' : '否'}',
                                            style: TextStyle(
                                              color: Color(0xff666666),
                                              fontSize: 12,
                                              height: 1,
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: setWidth(15),
                                    ),
                                    // if (state.showhou['guarantee_duration'] !=
                                    //     null)
                                    if (state.showhou['guarantee_sign'] == 1)
                                      Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Container(
                                            width: setWidth(250),
                                            child: Text(
                                              '保修时长:',
                                              style: TextStyle(
                                                color: Color(0xff222222),
                                                fontSize: 12,
                                                height: 1,
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Text(
                                              '${state.showhou['guarantee_duration'].toString().replaceAll('.0', '')}${state.showhou['guarantee_duration_units'] == 1 ? '年' : state.showhou['guarantee_duration_units'] == 2 ? '月' : '日'}',
                                              style: TextStyle(
                                                color: Color(0xff666666),
                                                fontSize: 12,
                                                height: 1,
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                  ],
                                ))
                      : Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: childrenList
                              .where((element) => element['name'] != null)
                              .toList()
                              .asMap()
                              .map((index, value) {
                                return MapEntry(
                                  index,
                                  Column(
                                    children: [
                                      SizedBox(
                                        height: setWidth(8),
                                      ),
                                      Row(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Container(
                                            width: setWidth(250),
                                            child: Text(
                                              '${value['name']}：',
                                              style: TextStyle(
                                                color: Color(0xff222222),
                                                fontSize: 12,
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                            child: Text(
                                              '${value['alias']}',
                                              style: TextStyle(
                                                color: Color(0xff666666),
                                                fontSize: 12,
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ],
                                  ),
                                );
                              })
                              .values
                              .toList(),
                        ),
                ),
              ],
            ),
          )
        : Container();
  }

  //  优惠券类型
  Widget _couponType(String typeIndex) {
    var type = '折扣券';
    if (typeIndex == '0') {
      type = '折扣券';
    } else if (typeIndex == '1') {
      type = '现金券';
    } else if (typeIndex == '2') {
      type = '免邮券';
    } else if (typeIndex == '8') {
      type = '兑换券';
    }

    return Container(
      child: Text(
        type,
        style: TextStyle(
          color: Color(0xffa5673f),
          fontSize: 16,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }

  List<Widget> _newList(dynamic adList, int index) {
    var commonWidgets = List<Widget>();
    for (var item in adList) {
      var goodList = jsonDecode(item['goods_list_json']);
      // if (goodList[state.shopId] != null) {
      //   print('9999990000-${goodList[state.shopId]}');
      // }
      // if (goodList[state.shopId] != null) {
      //   print('9999991111-${goodList[state.shopId][0]['style_num_id']}');
      // }

      if (item['adv_type'] == '1' &&
          item['adv_location'] == index &&
          goodList[state.shopId] != null &&
          goodList[state.shopId][0]['style_num_id'].toString() ==
              state.styleNumId.toString()) {
        commonWidgets.add(
          Container(
            margin: EdgeInsets.only(bottom: 20.w),
            child: Stack(
              children: <Widget>[
                new Image(
                  width: 750.r,
                  height: 375.r,
                  fit: BoxFit.fill,
                  image: new NetworkImage(
                    item['adv_object_url'],
                  ),
                ),
                item['tag_name'] != null
                    ? Positioned(
                        //方法二
                        right: 20.w,
                        bottom: 20.w,
                        child: new Container(
                          padding: EdgeInsets.only(
                            left: 6.0,
                            right: 6.0,
                            top: 2.0,
                            bottom: 2.0,
                          ),
                          decoration: BoxDecoration(
                            border: Border.all(
                              width: 1,
                              color: Color(0xff708090),
                            ),
                            borderRadius: BorderRadius.all(
                              Radius.circular(10),
                            ),
                          ),
                          child: Text(
                            item['tag_name'],
                            style: TextStyle(
                              color: Color(0xff708090),
                              fontSize: 10,
                            ),
                          ),
                        ),
                      )
                    : Container(),
              ],
            ),
          ),
        );
      } else if (item['adv_type'] == '2' &&
              item['adv_location'] == index &&
              goodList[state.shopId] != null
          //&&
          //jsonDecode(item['goods_list_json'])[state.shopId][0]['style_num_id'] .toString() ==   state.styleNumId.toString()
          ) {
        bool _found = false;
        if (goodList[state.shopId] != null) {
          List gs = goodList[state.shopId];
          gs.forEach((element) {
            if (element['style_num_id'].toString() ==
                state.styleNumId.toString()) {
              _found = true;
            }
          });
          if (_found == true) {
            commonWidgets.add(
              Container(
                margin: EdgeInsets.only(bottom: 20.w),
                child: Stack(
                  children: <Widget>[
                    new VideoPlayerPlus(
                      VideoPlayerController.network(
                        item['adv_object_url'],
                        videoPlayerOptions: VideoPlayerOptions(
                          mixWithOthers: true,
                        ),
                      ),
                    ),
                    item['tag_name'] != null
                        ? Positioned(
                            //方法二
                            right: 20.w,
                            bottom: 20.w,
                            child: new Container(
                              padding: EdgeInsets.only(
                                left: 6.0,
                                right: 6.0,
                                top: 2.0,
                                bottom: 2.0,
                              ),
                              decoration: BoxDecoration(
                                // color: Color(0xff708090),
                                border: Border.all(
                                  width: 1,
                                  color: Color(0xff708090),
                                ),
                                borderRadius: BorderRadius.all(
                                  Radius.circular(10),
                                ),
                              ),
                              child: Text(
                                item['tag_name'],
                                style: TextStyle(
                                  color: Color(0xff708090),
                                  fontSize: 20,
                                ),
                              ),
                            ),
                          )
                        : Container(),
                  ],
                ),
              ),
            );
          }
        }
      } else if (item['adv_type'] == '3' &&
          item['adv_location'] == index &&
          goodList[state.shopId] != null &&
          jsonDecode(item['goods_list_json'])[state.shopId][0]['style_num_id']
                  .toString() ==
              state.styleNumId.toString()) {
        Map<String, dynamic> user = jsonDecode(item['style_num_name']);
        user.forEach((key, value) {
          value[0]['shop_num_id'] = key;
          item['mdms_style'] = value[0];
        });
        commonWidgets.add(
          InkWell(
            onTap: () {
              String itemNumId =
                  item['mdms_style']['default_item_num_id'].toString();
              String styleNumId = item['mdms_style']['style_num_id'].toString();
              String ecStyleNumId =
                  item['mdms_style']['ec_style_num_id'].toString();
              state.styleNumId = styleNumId;
              Get.offAndToNamed(RouteConfig.goodsDetail, arguments: {
                'itemNumId': itemNumId,
                'styleNumId': styleNumId,
                'shopId': item['mdms_style']['shop_num_id'],
                'ecStyleNumId': ecStyleNumId,
                'typeIndex': item['mdms_style']['is_pre_sale'] ?? 0,
              });
            },
            child: Container(
              margin: EdgeInsets.only(bottom: 20.w),
              padding: EdgeInsets.only(
                  left: 30.w, right: 30.w, top: 25.w, bottom: 15.w),
              decoration: BoxDecoration(
                  boxShadow: [BoxShadow(color: Colors.grey, blurRadius: 5.0.w)],
                  color: Colors.white,
                  borderRadius: new BorderRadius.circular((20.0.w))),
              child: Column(
                children: [
                  // Container(
                  //   alignment: Alignment.centerLeft,
                  //   margin: EdgeInsets.only(right: 10.w, bottom: 30.w),
                  //   child: Text(
                  //     item['mdms_style']['title'],
                  //     style: TextStyle(
                  //       color: Color(0xff333333),
                  //       fontWeight: FontWeight.bold,
                  //       fontSize: 32.w,
                  //     ),
                  //   ),
                  // ),
                  Container(
                    constraints: BoxConstraints(minHeight: 250.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          // width: 300.w,
                          child: Image.network(
                            item['mdms_style']['image_default_id'],
                            width: 250.w,
                            height: 220.w,
                            fit: BoxFit.cover,
                          ),
                        ),
                        Expanded(
                          child: Container(
                            margin: EdgeInsets.only(left: 30.w),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                  alignment: Alignment.centerLeft,
                                  child: Text(
                                    item['mdms_style']['style_num_name'],
                                    style: TextStyle(
                                      color: Color(0xff666666),
                                      fontWeight: FontWeight.bold,
                                      fontSize: 30.w,
                                    ),
                                  ),
                                ),
                                Stack(
                                  children: [
                                    item['tag_name'] != null
                                        ? Positioned(
                                            //方法二
                                            right: 0,
                                            bottom: 0,
                                            child: new Container(
                                              padding: EdgeInsets.only(
                                                left: 6.0,
                                                right: 6.0,
                                                top: 2.0,
                                                bottom: 2.0,
                                              ),
                                              decoration: BoxDecoration(
                                                // color: Color(0xff708090),
                                                border: Border.all(
                                                  width: 1,
                                                  color: Color(0xff708090),
                                                ),
                                                borderRadius: BorderRadius.all(
                                                  Radius.circular(30),
                                                ),
                                              ),
                                              child: Text(
                                                item['tag_name'],
                                                style: TextStyle(
                                                  color: Color(0xff708090),
                                                  fontSize: 10,
                                                ),
                                              ),
                                            ),
                                          )
                                        : Container(),
                                    Container(
                                      alignment: Alignment.centerLeft,
                                      margin: EdgeInsets.only(top: 80.w),
                                      child: Text(
                                        '¥ ${item['mdms_style']['price']}',
                                        style: TextStyle(
                                          color: Color(0xff666666),
                                          fontWeight: FontWeight.bold,
                                          fontSize: 30.w,
                                        ),
                                      ),
                                    ),
                                  ],
                                )
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      } else if (item['adv_type'] == '4' &&
          item['adv_location'] == index &&
          goodList[state.shopId] != null &&
          jsonDecode(item['goods_list_json'])[state.shopId][0]['style_num_id']
                  .toString() ==
              state.styleNumId.toString()) {
        commonWidgets.add(
          InkWell(
            onTap: () {
              // 拼团
              if (item['results'][0]['ecactivity_classify'] == 1) {
                Map<String, dynamic> map = {
                  'icon_name': item['activity_num_name'],
                  'activity_num_id': item['activity_num_id'],
                  'pic_url': '',
                  'linktype': 9,
                  'linktarget': null,
                  'shop_id': item['results'][0]['ec_shop_num_id']
                };
                Get.toNamed(
                  RouteConfig.collage,
                  arguments: {'model': map},
                );
              } else if (item['results'][0]['ecactivity_classify'] == 2) {
                // 限时秒杀
                Map<String, dynamic> map = {'results': item['results']};
                Get.toNamed(
                  RouteConfig.seckillHome,
                  parameters: {},
                  arguments: {'model': map},
                );
              } else if (item['results'][0]['ecactivity_classify'] == 3) {
                // 预售
                Map<String, dynamic> map = {
                  'icon_name': item['activity_num_name'],
                  'pic_url': '',
                  'linktype': 12,
                  'linktarget': item['results'][0]['ecactivity_id'],
                  'shop_id': item['results'][0]['ec_shop_num_id'],
                };
                Get.toNamed(
                  RouteConfig.preSaleActive,
                  arguments: {'model': map},
                );
              } else {
                Map<String, dynamic> map = {
                  'icon_name': item['activity_num_name'],
                  'activity_num_id': item['activity_num_id'],
                  'pic_url': '',
                  'linktype': 9,
                  'linktarget': null
                };
                Get.toNamed(
                  RouteConfig.collage,
                  arguments: {'model': map},
                );
              }
            },
            child: Container(
              margin: EdgeInsets.only(bottom: 20.w),
              child: Stack(
                children: <Widget>[
                  item['results'].length != 0
                      ? new Image(
                          image: new NetworkImage(
                            item['activity_cover_url'],
                          ),
                        )
                      : Container(),
                  item['tag_name'] != null && item['results'].length != 0
                      ? Positioned(
                          //方法二
                          right: 20.w,
                          bottom: 20.w,
                          child: new Container(
                            padding: EdgeInsets.only(
                              left: 6.0,
                              right: 6.0,
                              top: 2.0,
                              bottom: 2.0,
                            ),
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 1,
                                color: Color(0xff708090),
                              ),
                              borderRadius: BorderRadius.all(
                                Radius.circular(30),
                              ),
                            ),
                            child: Text(
                              item['tag_name'],
                              style: TextStyle(
                                color: Color(0xff708090),
                                fontSize: 10,
                              ),
                            ),
                          ),
                        )
                      : Container(),
                ],
              ),
            ),
          ),
        );
      } else if (item['adv_type'] == '5' &&
          item['adv_location'] == index &&
          goodList[state.shopId] != null &&
          jsonDecode(item['goods_list_json'])[state.shopId][0]['style_num_id']
                  .toString() ==
              state.styleNumId.toString()) {
        var data = jsonDecode(item['coupon_num_name']);
        commonWidgets.add(
          Container(
            child: ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              itemExtent: 160.0,
              itemCount: data.length,
              itemBuilder: (ctx, index) {
                return InkWell(
                  onTap: data[index]['cover_url'] == null
                      ? () {}
                      : () {
                          toast('领取中...');
                          var params = {
                            "use_platform": 2,
                            "coupon_num_id":
                                data[index]['series'].toString(), //券编码
                            "usr_num_id": SpUtil.getInt('empeNumId'),
                            "access_token": SpUtil.getString('token'),
                            "relation": "领券中心",
                            "qsource": 301,
                            "relation_indate": "永久有效",
                            "user_num_id": SpUtil.getInt('empeNumId'),
                          };
                          Api.getCoupon(params).listen(
                            (event) {
                              toastDismissOther(event['message']);
                            },
                          );
                        },
                  child: Container(
                    constraints: new BoxConstraints.expand(
                      height: 134.0,
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(4.0),
                      image: DecorationImage(
                        image: NetworkImage("${data[index]['cover_url']}"),
                        fit: BoxFit.cover,
                      ),
                      color: Color(0xfff2c899),
                    ),
                    margin: EdgeInsets.only(bottom: 20.w, top: 20.w),
                    child: Row(
                      children: data[index]['cover_url'] != null
                          ? []
                          : [
                              Container(
                                width: 100.0,
                                margin: EdgeInsets.only(right: 20.w),
                                padding: EdgeInsets.only(left: 20.w),
                                child: Column(
                                  children: [
                                    Container(
                                      height: 30,
                                    ),
                                    data[index]['coupontype'] == '0'
                                        ? Row(
                                            children: [
                                              Text(
                                                '${data[index]['face_value'] / 10}',
                                                style: TextStyle(
                                                  color: Color(0xffa5673f),
                                                  fontSize: 36.0,
                                                ),
                                              ),
                                              Text(
                                                '折',
                                                style: TextStyle(
                                                  color: Color(0xffa5673f),
                                                ),
                                              ),
                                            ],
                                          )
                                        : Row(
                                            children: [
                                              Text(
                                                '¥',
                                                style: TextStyle(
                                                  color: Color(0xffa5673f),
                                                ),
                                              ),
                                              Text(
                                                '${data[index]['face_value']}',
                                                style: TextStyle(
                                                  color: Color(0xffa5673f),
                                                  fontSize: 36.0,
                                                ),
                                              ),
                                            ],
                                          ),
                                    Container(
                                      margin: EdgeInsets.only(top: 4.0),
                                      child: _couponType(
                                          data[index]['coupontype']),
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: Stack(
                                  children: [
                                    item['tag_name'] != null
                                        ? Positioned(
                                            //方法二
                                            right: 20.w,
                                            bottom: 20.w,
                                            child: new Container(
                                              padding: EdgeInsets.only(
                                                left: 6.0,
                                                right: 6.0,
                                                top: 2.0,
                                                bottom: 2.0,
                                              ),
                                              decoration: BoxDecoration(
                                                border: Border.all(
                                                  width: 1,
                                                  color: Color(0xff708090),
                                                ),
                                                borderRadius: BorderRadius.all(
                                                  Radius.circular(10),
                                                ),
                                              ),
                                              child: Text(
                                                item['tag_name'],
                                                style: TextStyle(
                                                  color: Color(0xff708090),
                                                  fontSize: 10,
                                                ),
                                              ),
                                            ),
                                          )
                                        : Container(),
                                    Container(
                                      // width: 400.w,
                                      child: Column(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Container(
                                            margin:
                                                EdgeInsets.only(bottom: 10.0),
                                            padding: EdgeInsets.only(top: 18.w),
                                            child: Text(
                                              data[index]['title'],
                                              style: TextStyle(
                                                color: Color(0xff000000),
                                                fontSize: 18.0,
                                              ),
                                            ),
                                          ),
                                          Container(
                                            child: item['start_time'] != null &&
                                                    item['end_time'] != null
                                                ? _getDate(item['start_time'],
                                                    item['end_time'])
                                                : Container(),
                                          ),
                                          InkWell(
                                            onTap: () {
                                              toast('领取中...');
                                              var params = {
                                                "use_platform": 2,
                                                "coupon_num_id": data[index]
                                                        ['series']
                                                    .toString(), //券编码
                                                "usr_num_id":
                                                    SpUtil.getInt('empeNumId'),
                                                "access_token":
                                                    SpUtil.getString('token'),
                                                "relation": "领券中心",
                                                "qsource": 301,
                                                "relation_indate": "永久有效",
                                                "user_num_id":
                                                    SpUtil.getInt('empeNumId'),
                                              };
                                              Api.getCoupon(params).listen(
                                                (event) {
                                                  toastDismissOther(
                                                      event['message']);
                                                },
                                              );
                                            },
                                            child: Container(
                                              padding: EdgeInsets.only(
                                                left: 10.0,
                                                right: 10.0,
                                                top: 4.0,
                                                bottom: 8.0,
                                              ),
                                              margin:
                                                  EdgeInsets.only(bottom: 20.w),
                                              decoration: BoxDecoration(
                                                color: Color(0xffa5673f),
                                                borderRadius:
                                                    BorderRadius.circular(20.0),
                                              ),
                                              child: Text(
                                                '立即领取',
                                                style: TextStyle(
                                                  color: Color(0xffffffff),
                                                  fontSize: 16,
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ],
                    ),
                  ),
                );
              },
            ),
          ),
        );
      }
    }
    return commonWidgets;
  }

  Widget _getDate(start, end) {
    var startTime = start.split(" ")[0];
    var endTime = end.split(" ")[0];
    return Container(
      // width: 300.w,
      margin: EdgeInsets.only(bottom: 10.0),
      child: Text(
        '有效期 $startTime -- $endTime',
        style: TextStyle(
          color: Color(0xff333333),
        ),
      ),
    );
  }

  // 图文详情
  Widget richTextDetailLayout() {
    initViewsAnchor('图文');

    return Container(
      key: _richContentLayoutKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: const EdgeInsets.only(left: 10, top: 15, bottom: 10),
            child: Text(
              '图文详情',
              style: TextStyle(
                fontSize: 16,
                color: const Color(0xFF222222),
                fontWeight: FontWeight.w500,
              ),
            ),
          ),

          // 商品详情头部广告
          state.advertising.length > 0
              ? Container(
                  margin: EdgeInsets.only(right: 20.w, left: 20.w),
                  child: Column(
                    children: _newList(state.advertising, 0),
                  ),
                )
              : Container(),
          //  state.richText == null ||state.richText['head_desc'] == null?Container():Html(data: state.richText['head_desc'].toString()),
          // 图文详情头部
          // Html(data: state.richText['head_desc'].toString()),
          _detailHeader(),
          // 图文详情中部
          // Html(data: state.richText['wap_desc'].toString()),
          _detailWapDesc(),
          // 图文详情尾部
          // Html(data: state.richText['end_desc'].toString()),
          _detailEndDesc(),
          // 商品详情尾部广告
          state.advertising.length > 0
              ? Container(
                  margin: EdgeInsets.only(right: 20.w, left: 20.w),
                  child: Column(
                    children: _newList(state.advertising, 2),
                  ),
                )
              : Container(),
        ],
      ),
    );
  }

  // 图文详情头部
  Widget _detailHeader() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['head_desc'] == null ||
        state.richText['head_desc'].toString().isEmpty) {
      return Container();
    }
    return Html(data: state.richText['head_desc'].toString());
  }

  // 图文详情中部
  Widget _detailWapDesc() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['wap_desc'] == null ||
        state.richText['wap_desc'].toString().isEmpty) {
      return Container();
    }
    return Html(data: state.richText['wap_desc'].toString());
  }

  // 图文详情尾部
  Widget _detailEndDesc() {
    if (state.richText == null ||
        state.richText.toString().isEmpty ||
        state.richText['end_desc'] == null ||
        state.richText['end_desc'].toString().isEmpty) {
      return Container();
    }
    return Html(data: state.richText['end_desc'].toString());
  }

  void showShareBottomSheet(BuildContext context) {
    Widget _shareItem(String assetImage, String title) {
      return Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image(
            image: AssetImage(assetImage),
            width: 50,
            height: 50,
          ),
          SizedBox(width: 20, height: 10),
          Text(
            title,
            style: TextStyle(
              fontSize: 14,
              color: Color(0xff666666),
            ),
          )
        ],
      );
    }

    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        builder: (BuildContext context) {
          return Container(
            height: MediaQuery.of(context).size.height / 3,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10), topRight: Radius.circular(10)),
            ),
            child: Stack(
              children: [
                Align(
                  alignment: Alignment.topRight,
                  child: GestureDetector(
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(18.0),
                      child: Image(
                        image: AssetImage("assets/images/close.png"),
                        width: 20,
                        height: 20,
                      ),
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      GestureDetector(
                          onTap: () {
                            logic.shareToFriend();
                            // logic.shareToFriend1();
                            Navigator.of(context).pop();
                          },
                          child:
                              _shareItem("assets/images/share1.png", "微信好友")),
                      SizedBox(width: 20, height: 20),
                      GestureDetector(
                          onTap: () {
                            logic.shareToWechatCircle();
                            Navigator.of(context).pop();
                          },
                          child: _shareItem("assets/images/share4.png", "朋友圈")),
                      SizedBox(width: 20, height: 20),
                      GestureDetector(
                          onTap: () {
                            logic.requestPosterData(state.goodsDetail,
                                (qrCode) {
                              _showSharePosterDialog(qrCode);
                            });
                            Navigator.of(context).pop();
                          },
                          child:
                              _shareItem("assets/images/poster.png", "生成海报")),
                      SizedBox(width: 20, height: 20),
                      GestureDetector(
                          onTap: () {
                            logic.CopyLink();
                            Navigator.of(context).pop();
                          },
                          child:
                          _shareItem("assets/images/share5.png", "复制链接")),
                    ],
                  ),
                ),
              ],
            ),
          );
        },
        context: context);
  }

  void _showSharePosterDialog(String qrCode) {
    showModal(
      context: context,
      //动画过渡配置
      configuration: FadeScaleTransitionConfiguration(
        //阴影背景颜色
        barrierColor: Colors.black54,
        //打开新的Widget 的时间
        transitionDuration: Duration(milliseconds: 1000),
        //关闭新的Widget 的时间
        reverseTransitionDuration: Duration(milliseconds: 1000),
      ),
      builder: (BuildContext context) {
        //显示的Widget
        return buildQrcodeModal(context, qrCode);
      },
    );
  }

  GlobalKey repaintWidgetKey = GlobalKey();

  Widget buildQrcodeModal(BuildContext context, String qrCode) {
    print(
        '++++++++++++++++++++++++ state.qrCode ++++++++++++++++++++++++ qrCode = $qrCode');
    String goodsImageUrl = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['image_default_id']
        : null;
    num expectPrice = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['expect_price']
        : null;
    num price = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['price']
        : null;
    num soldQuantity = state.goodsDetail != null
        ? (state.goodsDetail['sold_quantity'] ?? 0)
        : 0;

    num mktPrice = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['mkt_price']
        : 0;
    String itemName = state.goodsDetail != null &&
            state.goodsDetail['spec_item_detail'] != null
        ? state.goodsDetail['spec_item_detail']['item_name']
        : '';
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Align(
            child: GestureDetector(
              onTap: () {
                Navigator.pop(context);
              },
              child: Padding(
                padding: EdgeInsets.only(right: 30.w),
                child: Image.asset(
                  "assets/images/closeqrcode.png",
                  width: 60.w,
                ),
              ),
            ),
            alignment: Alignment.centerRight,
          ),
          SizedBox(height: 20.w),
          RepaintBoundary(
            key: repaintWidgetKey,
            child: Container(
              width: 654.w,
              height: 1000.w,
              padding: EdgeInsets.symmetric(
                vertical: 25.w,
                horizontal: 25.w,
              ),
              decoration: BoxDecoration(
                  image: DecorationImage(
                image: AssetImage("assets/images/qrcode.png"),
                fit: BoxFit.fitWidth,
              )),
              child: Column(
                children: [
                  Row(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.all(
                          Radius.circular(100.w),
                        ),
                        child: Image.asset(
                          "assets/images/avatar.png",
                          width: 64.w,
                        ),
                      ),
                      SizedBox(
                        width: 20.w,
                      ),
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              SpUtil.getString('empeName'),
                              style: TextStyle(
                                fontSize: 30.sp,
                                color: Colors.white,
                                decoration: TextDecoration.none,
                              ),
                            ),
                            Text(
                              "为您挑选了一个好物～",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 22.sp,
                                color: Colors.white,
                                decoration: TextDecoration.none,
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      top: 60.w,
                    ),
                    padding: EdgeInsets.symmetric(
                      horizontal: 35.w,
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          width: 530.w,
                          height: 520.w,
                          child: goodsImageUrl != null
                              ? Image.network(
                                  goodsImageUrl,
                                  width: 530.w,
                                  height: 520.w,
                                )
                              : Container(
                                  width: 530.w,
                                  height: 520.w,
                                ),
                        ),
                        SizedBox(
                          height: 20.w,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            RichText(
                              text: TextSpan(
                                children: [
                                  TextSpan(
                                    text: '折后价 ¥',
                                    style: TextStyle(
                                      color: Color(0xffD0021B),
                                      fontSize: 24.w,
                                      decoration: TextDecoration.none,
                                    ),
                                  ),
                                  TextSpan(
                                    text: expectPrice != null && expectPrice > 0
                                        ? expectPrice.toString()
                                        : '$price',
                                    style: TextStyle(
                                      color: Color(0xffD0021B),
                                      fontSize: 38.w,
                                      decoration: TextDecoration.none,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            state.goodsDetail['is_show_sold_qty'] == 0
                                ? Text('')
                                : Text(
                                    "已售${soldQuantity.toString().replaceAll(".0", "")}件",
                                    style: TextStyle(
                                      fontSize: 24.sp,
                                      color: Color(0xffA3A3A3),
                                      decoration: TextDecoration.none,
                                    ),
                                  ),
                          ],
                        ),
                        SizedBox(
                          height: 20.w,
                        ),
                        Text(
                          '¥$mktPrice',
                          style: TextStyle(
                            fontSize: 28.sp,
                            color: Color(0xffA3A3A3),
                            decoration: TextDecoration.none,
                          ),
                        ),
                        SizedBox(
                          height: 10.w,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Container(
                              width: 300.w,
                              child: Text(
                                '$itemName',
                                style: TextStyle(
                                  fontSize: 28.sp,
                                  color: Color(0xff262626),
                                  decoration: TextDecoration.none,
                                ),
                                maxLines: 3,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                            if (qrCode.isNotEmpty)
                              ClipRRect(
                                borderRadius: BorderRadius.all(
                                  Radius.circular(100.w),
                                ),
                                child: Image.network(
                                  qrCode,
                                  width: 140.w,
                                ),
                              ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
          GestureDetector(
            onTap: () async {
              bool hasLocationPermission = await requestLocationPermission();
              if (hasLocationPermission) {
                BuildContext buildContext = repaintWidgetKey.currentContext;
                RenderRepaintBoundary boundary =
                    buildContext.findRenderObject();
                ui.Image image = await boundary.toImage(pixelRatio: 3.0);
                ByteData byteData =
                    await image.toByteData(format: ui.ImageByteFormat.png);
                final result = await ImageGallerySaver.saveImage(
                    byteData.buffer.asUint8List());
                print(result);
                // toast('保存成功');
                Navigator.pop(context);
                print("定位权限申请通过");
              } else {
                print("定位权限申请不通过");
              }
              showModal(
                context: context,
                //动画过渡配置
                configuration: FadeScaleTransitionConfiguration(
                  //阴影背景颜色
                  barrierColor: Colors.black54,
                  //打开新的Widget 的时间
                  transitionDuration: Duration(milliseconds: 1000),
                  //关闭新的Widget 的时间
                  reverseTransitionDuration: Duration(milliseconds: 1000),
                ),
                builder: (BuildContext context) {
                  //显示的Widget
                  return buildSuccessModal(context);
                },
              );
            },
            child: Container(
              width: 400.w,
              height: 80.w,
              margin: EdgeInsets.only(top: 30.w),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(
                  Radius.circular(100),
                ),
                border: Border.all(color: Colors.white),
              ),
              child: Center(
                child: Text(
                  "保存图片",
                  style: TextStyle(
                    fontSize: 34.sp,
                    color: Colors.white,
                    decoration: TextDecoration.none,
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  Center buildSuccessModal(BuildContext context) {
    return Center(
      child: Container(
        width: 490.w,
        height: 220.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(
            Radius.circular(30.w),
          ),
        ),
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.only(left: 50.w),
              child: Column(
                children: [
                  SizedBox(height: 50.w),
                  // Row(
                  //   mainAxisAlignment: MainAxisAlignment.start,
                  //   children: [
                  //     Image.asset(
                  //       "assets/images/save.png",
                  //       width: 30.w,
                  //     ),
                  //     SizedBox(width: 20.w),
                  //     Text(
                  //       "文案已复制",
                  //       style: TextStyle(
                  //         fontSize: 28.sp,
                  //         color: Color(0xff222222),
                  //       ),
                  //     )
                  //   ],
                  // ),
                  // SizedBox(height: 40.w),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Image.asset(
                        "assets/images/save.png",
                        width: 30.w,
                      ),
                      SizedBox(width: 20.w),
                      Text(
                        "图片已保存到相册",
                        style: TextStyle(
                          fontSize: 28.sp,
                          color: Color(0xff222222),
                        ),
                      )
                    ],
                  ),

                  SizedBox(height: 40.w),
                ],
              ),
            ),
            Divider(
              color: Color(0xffeeeeee),
              height: .2,
            ),
            SizedBox(height: 15.w),
            InkWell(
              onTap: () {
                Navigator.pop(context);
              },
              child: Container(
                width: 750.w,
                child: Center(
                  child: Text(
                    "我知道了",
                    style: TextStyle(
                      fontSize: 32.sp,
                      color: Config.mainColor,
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Future<bool> requestLocationPermission() async {
    //获取当前的权限
    var status = await Permission.storage.status;
    if (status == PermissionStatus.granted) {
      //已经授权
      return true;
    } else {
      //如果客户拒绝过一次，则不再申请权限
      if (SpUtil.getBool('Permissionstoragestatus') == true) {
        toast('请在手机设置中授予存储访问权限');
        return false;
      }
      //未授权则发起一次申请
      status = await Permission.storage.request();
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        SpUtil.putBool('Permissionstoragestatus', true);
        return false;
      }
    }
  }

  void _gotoCommentListPage() {
    Get.toNamed(RouteConfig.goodsCommentList,
        arguments: {"styleNumId": logic.styleNumId});
  }

  // 收货地址
  Widget _receiveAddress() {
    return Visibility(
      visible: (state.addressAllString.length > 0),
      child: Container(
        padding: EdgeInsets.only(left: 10, top: 0, right: 10, bottom: 0),
        child: Row(
          children: [
            Text('送至'),
            Expanded(
              child: Padding(
                  padding: EdgeInsets.symmetric(horizontal: 10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        state.addressAllString,
                        // logic.getCurrentLocationDescription(),
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 14,
                          // color: Config.mainColor,
                        ),
                      ),
                      _distributionScopeView(),
                    ],
                  )),
            ),
            IconButton(
                onPressed: () {
                  Get.toNamed(RouteConfig.addressList).then((value) {
                    if (value != null) {
                      changeSelectAddress(value["address"]);
                      getCurrentLocationInfo(success: (data) {
                        state.addressAllString = data['addressAllString'];
                        state.addressInfo = data['addressInfo'];
                        logic.requestDetail();
                      });
                    }
                  });
                },
                icon: Image.asset(
                  'assets/images/more.png',
                  width: 20,
                  height: 6,
                )),
          ],
        ),
      ),
    );
  }

  // 配送范围
  Widget _distributionScopeView() {
    if (state.deliveryType == 0) {
      return Text(
        '无货，该商品在该地区暂不支持销售',
        style: TextStyle(
          fontSize: 14,
          color: const Color(0xFFAAAAAA),
        ),
      );
    } else {
      return Text(
        '现货',
        style: TextStyle(
          fontSize: 14,
          color: Colors.red,
        ),
      );
    }
  }

  // 超出配送范围
  Widget _overDeliveryView() {
    return Visibility(
      visible: (state.deliveryType == 0),
      child: Container(
        width: 200,
        height: 40,
        padding: EdgeInsets.symmetric(horizontal: 10),
        margin: EdgeInsets.only(right: 10),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Color(0xFFE89E42),
          borderRadius: BorderRadius.all(
            Radius.circular(20),
          ),
        ),
        child: Text(
          '超出配送范围',
          style: TextStyle(
            fontSize: 14,
            color: Colors.white,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }

  // 超出配送范围-提示
  Widget _overDeliveryTipView() {
    return Visibility(
      visible: (state.deliveryType == 0),
      child: Positioned(
        //方法二
        bottom: 0,
        child: Container(
          width: 750.w,
          height: 80.w,
          padding: EdgeInsets.symmetric(horizontal: 8),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Color(0xFFFCF9DF),
          ),
          child: Text(
            '所选地区暂时无货，非常抱歉！',
            style: TextStyle(
              fontSize: 14,
              color: Color(0xFFE89E42),
              fontWeight: FontWeight.w500,
            ),
          ),
        ),
      ),
    );
  }

  // 评论
  Widget _commentLayout() {
    if (state.comment == null || state.comment['list'] == null) {
      return Container(
        key: _commentLayoutKey,
        child: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Row(
            children: [
              Text(
                '顾客评价',
                style: TextStyle(
                  fontSize: 16,
                  color: const Color(0xFF222222),
                  fontWeight: FontWeight.w500,
                ),
                textAlign: TextAlign.left,
              ),
            ],
          ),
        ),
      );
    }
    List list = state.comment['list'];
    if (list == null || list.isEmpty) {
      return Container(
        key: _commentLayoutKey,
        child: Padding(
          padding: const EdgeInsets.all(10.0),
          child: Row(
            children: [
              Text(
                '顾客评价',
                style: TextStyle(
                  fontSize: 16,
                  color: const Color(0xFF222222),
                  fontWeight: FontWeight.w500,
                ),
                textAlign: TextAlign.left,
              ),
            ],
          ),
        ),
      );
    }
    var comment = list[0];
    String logoUrl = comment['logo'] ?? "";
    String userName = comment['nick_name'] ?? "";
    String totalCount = state.comment['total_count'] ?? "";
    int score = comment['result'] == null ? 0 : num.parse(comment['result']);
    String picsString = comment['list_video'] ?? "";
    List<String> picList = [];
    if (picsString != null && picsString.isNotEmpty) {
      picList = picsString.split(',');
    }

    String rateString = comment['rate_pic'] ?? "";
    List<String> rateList = [];
    if (rateString != null && rateString.isNotEmpty) {
      rateList = rateString.split(',');
    }

    if (rateList.length > 0) {
      picList.addAll(rateList);
    }

    initViewsAnchor('评价');
    return Container(
      key: _commentLayoutKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Expanded(
                child: Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Text(
                    (totalCount != null && totalCount.isNotEmpty)
                        ? '顾客评价($totalCount)'
                        : '顾客评价',
                    style: TextStyle(
                      fontSize: 16,
                      color: const Color(0xFF222222),
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              ),
              GestureDetector(
                // onTap: () => _gotoCommentListPage(),
                onTap: () {
                  print('品论点击事件！！！');
                  _gotoCommentListPage();
                },
                behavior: HitTestBehavior.opaque,
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 10),
                  child: Text(
                    '查看全部 ',
                    style: TextStyle(
                      fontSize: 12,
                      color: const Color(0xFFAAAAAA),
                    ),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(right: 10),
                child: Image.asset(
                  'assets/images/arrow_right.png',
                  width: 12,
                  height: 12,
                  fit: BoxFit.fill,
                ),
              ),
            ],
          ),
          _divider(1),
          Row(
            children: [
              Padding(
                padding: const EdgeInsets.all(11.0),
                child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(16)),
                  child: Image.network(
                    logoUrl,
                    width: 32,
                    height: 32,
                    fit: BoxFit.fill,
                    errorBuilder: (context, error, stackTrace) {
                      return Image.asset(
                        'assets/images/user1.png',
                        width: 32,
                        height: 32,
                        fit: BoxFit.fill,
                      );
                    },
                  ),
                ),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      comment["anony"] == 1 ? '匿名用户' : userName,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: 14,
                        color: const Color(0xFF222222),
                      ),
                    ),
                    Ratting(score: score),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(10.0),
                child: Text(
                  comment['created_time'],
                  style: TextStyle(
                    fontSize: 11,
                    color: Color(0xFFAAAAAA),
                  ),
                ),
              ),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 7),
            child: Text(
              comment['content'],
              style: TextStyle(
                fontSize: 12,
                color: Color(0xFF333333),
              ),
            ),
          ),
          Visibility(
            visible: picList.isNotEmpty,
            child: GridView.builder(
                padding: EdgeInsets.symmetric(horizontal: 10),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 4,
                  mainAxisSpacing: 10,
                  crossAxisSpacing: 10,
                  childAspectRatio: 1,
                ),
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                itemCount: picList.length,
                itemBuilder: (context, index) {
                  print(">>>>>>>>>>=======${picList[index]}");
                  if (picList[index].contains(".mp4")) {
                    return GestureDetector(
                      onTap: () {
                        Get.to(
                          VideoPlayerPlus(
                            VideoPlayerController.network(picList[index]),
                          ),
                        );
                      },
                      child: Stack(
                        alignment: Alignment.center,
                        children: [
                          Container(
                              width: double.infinity,
                              height: double.infinity,
                              margin: EdgeInsets.zero,
                              color: Colors.grey,
                              child: VideoApp(videoUrl: (picList[index]))),
                          Positioned(
                            child: Icon(Icons.play_circle_fill,
                                color: Colors.white),
                          )
                        ],
                      ),
                    );
                  }
                  return ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    // child: Image.network(
                    //   picList[index],
                    //   width: double.infinity,
                    //   height: double.infinity,
                    //   fit: BoxFit.fill,
                    // ),
                    child: GestureDetector(
                      onTap: () async {
                        Get.to(goodsPhotoGalleryPage(
                          picList
                              .where((element) => !element.contains(".mp4"))
                              .toList(),
                          currentIndex: index -
                              picList
                                  .where((element) => element.contains(".mp4"))
                                  .toList()
                                  .length,
                        ));
                      },
                      child: cacheImage(
                        imageUrl: picList[index],
                        width: double.infinity,
                        height: double.infinity,
                        fit: BoxFit.cover,
                      ),
                    ),
                  );
                }),
          ),
          SizedBox(height: 15),

        ],
      ),
    );
  }

  void showCouponDialog() {
    if (state.availableCoupons == null ||
        state.availableCoupons['card_tickets'] == null) {
      return;
    }
    List availableCouponList = state.availableCoupons['card_tickets'];
    if (availableCouponList == null || availableCouponList.isEmpty) {
      return;
    }
    List gotCouponList;
    if (state.gotCoupons != null && state.gotCoupons['usr_vouchers'] != null) {
      gotCouponList = state.gotCoupons['usr_vouchers'];
    }

    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        builder: (context) {
          return GetCouponBottomSheet(availableCouponList, gotCouponList);
        });
  }

  Widget shopInfoWidget() {
    return state.shopInfos != null
        ? Container(
            color: const Color(0xffffffff),
            padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
            child: InkWell(
              onTap: () {
                if (_kIsWeb) return;
                logic.goToThirdShop();
              },
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                      margin: const EdgeInsets.only(right: 10),
                      width: setWidth(100),
                      height: setWidth(100),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: const Color(0xfff4f4f4),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black12,
                            blurRadius: 2,
                          ),
                        ],
                      ),
                      child: Image.network(
                          state.shopInfos['ec_shop_logo'] == null ||
                                  state.shopInfos['ec_shop_logo'] == ''
                              ? Config.orderEmpty
                              : state.shopInfos['ec_shop_logo'])),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Expanded(
                              child: Text(
                                state.shopInfos['shop_name'] ?? '',
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: const Color(0xff333333),
                                  fontWeight: FontWeight.bold,
                                  fontSize: 15,
                                ),
                              ),
                            ),
                            _kIsWeb
                                ? SizedBox()
                                : Padding(
                                    padding: const EdgeInsets.only(right: 13),
                                    child: Image.asset(
                                      'assets/images/arrow_right.png',
                                      width: 20,
                                      height: 20,
                                    ),
                                  ),
                          ],
                        ),
                        SizedBox(height: 5),
                        _kIsWeb
                            ? SizedBox()
                            : Container(
                                decoration: BoxDecoration(
                                  border: Border.all(
                                    color: const Color(0xffCCCCCC),
                                  ),
                                  borderRadius: BorderRadius.circular(20),
                                ),
                                padding:
                                    const EdgeInsets.only(top: 3, bottom: 3),
                                width: 110,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Container(
                                      width: 12,
                                      margin: const EdgeInsets.only(right: 6),
                                      child: Image.asset(
                                        'assets/images/shopLogo.png',
                                        fit: BoxFit.fill,
                                      ),
                                    ),
                                    Text(
                                      '进店逛逛',
                                      style: TextStyle(
                                        color: const Color(0xff333333),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          )
        : SizedBox();
  }

  @override
  void dispose() async {
    super.dispose();
    await _stopWatchTimerDown.dispose();
  }
}
